Re: Passing strings to threads and memory leaks
Re: Passing strings to threads and memory leaks
- Subject: Re: Passing strings to threads and memory leaks
- From: Chuck Rice <email@hidden>
- Date: Fri, 7 May 2004 12:45:26 -0700
At 9:04 PM +0200 5/7/04, Pontus Ilbring wrote:
On 2004-05-07, at 20.05, Chuck Rice wrote:
Thanks! But I guess I still do not understand. If I release theData
at the end of the method, when the other thread executes, that
storage will be gone, won't it?
In the modified code I showed you, theData starts out with a retain
count of 1, because you created it with alloc. When you call retain
before storing it away the retain count becomes 2, and when you call
release at the end of the method its retain count becomes 1 again.
In the next iteration, when you release temp, its retain count falls
to 0 and it'll be deallocated. In this case, you could avoid calling
retain and release for theData altogether -- its retain count starts
out at 1 and would just stay at 1 until you release temp it in the
next iteration.
Coding the way I suggested merely saves you from even having to
think about the retain count.
That is what was missing in my understanding. Thanks! -Chuck-
--
Fight Spam! Join CAUCE! ==
http://www.cauce.org/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.