Re: autorelease - when is retain count decremented
Re: autorelease - when is retain count decremented
- Subject: Re: autorelease - when is retain count decremented
- From: Shawn Erickson <email@hidden>
- Date: Tue, 14 Sep 2004 14:26:10 -0700
On Sep 14, 2004, at 1:41 PM, justin webster wrote:
just wondering what causes the retain count of an object to drop.
this is the situation I've been wondering about:
NSString *myString = [NSString stringWithFormat:@"testing"];
myString = anotherString;
when I point myString away from the 'testing' string, does the
'testing' memory get freed?
No in this case it gets deallocated when the current autorelease pool
is deallocated.
or should I release myString before pointing it to something else?
In this case no.
also, in this situation do I now have two pointers to the same piece
of memory, and therefore a retain count of two?
No having a reference aka pointer to an object does not affect the
retain count in Cocoa. The retain count is managed by calls to
retain/release and indirectly by autorelease.
Instead of trying to explain what is going on in email please review
one of the many resources on this topic...
Apple's documentation...
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
index.html>
...in particular...
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
Concepts/ObjectOwnership.html>
Or in general...
<http://www.google.com/search?q=Cocoa+memory+management&ie=UTF
-8&oe=UTF-8>
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden