Re: dealloc for cleanup versus freeing memory
Re: dealloc for cleanup versus freeing memory
- Subject: Re: dealloc for cleanup versus freeing memory
- From: Chris Suter <email@hidden>
- Date: Tue, 7 Aug 2007 15:36:48 +1000
On 07/08/2007, at 3:09 PM, Kurt Bigler wrote:
But it is hard in retrospect to remember how often in C++ I ended up
releasing external resources in destructors. I'd have to do a code
survey
to find out. I just know that I've done it, and that the idea
never seemed
inherently wrong.
It's not wrong and there's nothing wrong with your approach. You
should always clean-up in dealloc methods but you have to allow a
different way of closing resources for those cases when you want to
control when the resources are freed. The point is that with
reference counting and garbage collection you don't know when that
clean-up will occur. This isn't specific to Objective C. I've come
across bugs where a release of an object was expected to release a
resource and problems occurred because it didn't (due to an
unexpected additional reference hanging around). Anybody porting
their code to use garbage collection will soon encounter these kinds
of bugs.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden