tag:blogger.com,1999:blog-3237724005744642470.post2796534442801627682..comments2020-09-27T17:41:07.221+01:00Comments on Captain Debug's Blog: Isn't Java a Civilised Language?Roger Hugheshttp://www.blogger.com/profile/07042290171112551665[email protected]Blogger6125tag:blogger.com,1999:blog-3237724005744642470.post-59435783617956983992012-03-01T06:54:52.481+00:002012-03-01T06:54:52.481+00:00I made exactely the same experiences. I am a java ...I made exactely the same experiences. I am a java developer since 2005 and wrote an iPad-App at the end of the last year. The memory management was quite confusing for me but in this time ARC was even more confusing because on some parts I had do call retain/release-methods anyway (when using Core Graphics). And this inconsequence made me mad. <br />It seems to me that ARC is not completed jet.Nina[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-81707228797423440022012-02-26T08:16:51.419+00:002012-02-26T08:16:51.419+00:00I can see you point on circular references, which ...I can see you point on circular references, which I guess is something that Apple have thought about. Without going into detail, when using automatic reference counting, you can tell the compiler that a reference to an object maybe 'unsafe' and not reference count it; hence if A->B->A, object B knows that it's reference is unsafe, and it doesn't reference count it, it just has a copy of a pointer back to A.<br /><br />In general terms - if you know a reference is unsafe, then your setter may look like this:<br /><br />-(void) mySetter:(A *)myA {<br /> _myA = myA;<br />}<br /><br />If you know that the pointer is safe, then you do something like this:<br /><br /><br />-(void) mySetter:(A *)myA {<br /> [_myA release];<br /> _myA = myA;<br /> [myA retain];<br />}<br /><br />...where _myA is you instance variable and 'retain' gives you ownership.Roger Hugheshttps://www.blogger.com/profile/07042290171112551665[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-70150545633577716332012-02-24T17:18:48.301+00:002012-02-24T17:18:48.301+00:00What about circular references? A pointing to B an...What about circular references? A pointing to B and B pointing to A. Or a more complex path, A -> B -> C -> D -> B...<br /><br />Does automatic compiler based retain/release calls just aggravate it?<br /><br />I remember from way back when that COM and DCOM fell flat on its face because of circular references. It made any complicated application a complete nightmare, completely unacceptable to work with. You always get leaks eventually.<br /><br />~MikeAnonymous[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-1497550895374696662012-02-24T12:36:00.965+00:002012-02-24T12:36:00.965+00:00Apple actually added garbage collection to Objecti...Apple actually added garbage collection to Objective-C before it added automatic reference counting. It never made it to iOS tho. And it has been abandoned again now.<br /><br />Automatic reference counting is not really doing anything automatic at runtime tho. It simply adds the retain and release calls in the per-processor. So it can still be messed up by bad code.Tiran Kenjahttps://www.blogger.com/profile/00149892231563027817[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-86547012343778619652012-02-23T18:42:39.277+00:002012-02-23T18:42:39.277+00:00This...
String msg = new String().withFormat(&quo...This...<br /><br />String msg = new String().withFormat("Processing an address page request for address with id: " + id);<br />logger.info(msg);<br />msg.release();<br /><br />should be...<br /><br />NSLog(@"blah %@",id);<br /><br />Which logs to console and syslog. Also note that NSString can return autoreleased strings, and you don't retain parameters on sync code.<br /><br />Here are the manual memory management rules of objc:<br /><br />1. If you new, alloc init, retain, or copy (NARC) an object, you have to release it.<br />2. If a method doesn't start with any of these words it returns an autoreleased object.<br /><br />You have to practice a bit, but it's just that.Anonymous[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-49595275830670101362012-02-23T15:23:43.417+00:002012-02-23T15:23:43.417+00:00Automatic Reference Counting (ARC) is a new featur...Automatic Reference Counting (ARC) is a new feature that Apple added to Objective-C which is supposed to generate the reference counting code for you. This is supposed to allow you to write simpler code without the slowdowns of a garbage collector.Blacktigerhttps://www.blogger.com/profile/02629290772651452425[email protected]