• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Appropriate dealloc and finalize actions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Screensaver won't run on 10.6 even after porting to 64-bit
  • Next by Date: drawing in uiview
  • Previous by thread: Re: Creating NSMatrix of NSImageCells
  • Next by thread: Re: Appropriate dealloc and finalize actions
  • Index(es):
    • Date
    • Thread