Appropriate dealloc and finalize actions
Appropriate dealloc and finalize actions
- Subject: Appropriate dealloc and finalize actions
- From: Karolis Ramanauskas <email@hidden>
- Date: Sun, 11 Oct 2009 15:56:19 -0500
Good day, everyone,
The situation is simple, I have two instances of the same class (MyClass).
This class has a connection instance variable and a declared property for
that variable:
@property (readwrite, assign) MyClass * connection;
So basically an object has a reference to another object of the same class.
Whenever I remove a one of these objects I check if self.connection is not
nil in a dealloc method and in that case I set other object's connection to
nil to make sure it will not point to a soon to be deallocated instance.
This is my dealloc method:
- (void)dealloc {
if (self.connection) {
self.connection.connection = nil;
}
[super dealloc];
}
All works well with no leaks, etc. However I wanted to make this GC
compatible and decided to include a finalize method with the same
expression. However from what I read in here:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcFinalize.html
this is discouraged. Am I misunderstanding what is being said? The
description of dealloc method doesn't seem to have the same language
associated with it:
<http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcFinalize.html>
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.htm
l
Thanks for any insight into this,
Karolis
_______________________________________________
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