• 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
Re: A legitimate argument for calling dealloc directly?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A legitimate argument for calling dealloc directly?


  • Subject: Re: A legitimate argument for calling dealloc directly?
  • From: Marcel Weiher <email@hidden>
  • Date: Tue, 14 Jan 2003 10:30:08 +0100

On Tuesday, January 14, 2003, at 01:52 Uhr, Daniel Jalkut wrote:

I am implementing a class of object that needs to periodically "reinitialize" itself (in response to changed files on disk). This class inherits from a class that is out of my direct control,

In this case, "safe" re-initialization is virtually impossible. Sorry.

so as far as I can tell the only "safe" way to make sure that both the super class and my own instance variables are "reset" is to manually call [self dealloc] and then [self init].

No, this isn't safe at all. -dealloc will not only deallocate instance variables, it will also release the memory for the object itself, so when you send -init, the object you are sending the message to ("self") has just been deallocated. This should give you instance core-dump satisfaction.

I know calling dealloc instead of release is discouraged, but in this case I don't want to release

But dealloc does exactly that.

and reallocate (the object is being managed in a data structure, and I'd like the data structure to keep the same "handle" on it).

After the dealloc, the handle is pointing to freed memory.

Is this totally skanky? Is there something dangerous I'm overlooking here?

Apart from the immediate core-dump? No ;-)

Marcel

--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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.

  • Follow-Ups:
    • Re: A legitimate argument for calling dealloc directly?
      • From: Daniel Jalkut <email@hidden>
References: 
 >A legitimate argument for calling dealloc directly? (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: Re: Aqua Human Interface and Safari
  • Next by Date: Re: WebCore and PDF
  • Previous by thread: Re: A legitimate argument for calling dealloc directly?
  • Next by thread: Re: A legitimate argument for calling dealloc directly?
  • Index(es):
    • Date
    • Thread