• 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: [self release] question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [self release] question...


  • Subject: Re: [self release] question...
  • From: Aurélien Hugelé <email@hidden>
  • Date: Sat, 20 Mar 2004 16:29:19 +0100

thanks for you help, things are now much simpler !
merci ;)

Le 20 mars 04, ` 15:41, Philippe Mougin a icrit :

As others stated, "[self release];" is a valid instruction, and can be useful.

Two remarks related to your situation:

- Instead of releasing your controller in windowShouldClose:, do it in windowWillClose:. Generally, you can't be sure that your window will really be closed until you receive the windowWillClose: message. In addition, doing this kind of cleanup in windowWillClose: better shows your intent.

- You must determine if, in your particular situation, the "[self release]" might lead to the immediate deallocation of your controller (when looking at this, take into consideration the fact that windows do not retain their delegates). If so, you must make sure that your controller instance will no more be used after its deallocation. In particular, you must ensure that the window will no more message your controller (its delegate). A good way to ensure that is for you controller to stop being the window's delegate before releasing itself.

Your windowWillClose: method might look like this:

- (void)windowWillClose:(NSNotification *)aNotification
{
[[aNotification object] setDelegate:nil];
[self release];
}

Best,

Philippe Mougin


> well i have a myWindowController (does *not* herit at all from NSWindowController...)
> which manage one and only one window.
> For me, the best solution would be to release the myWindowController when
> the user close the window it manages.
>
> the myWindowController implements the delegate method
> windowShouldClose: in the windowShouldClose:, can i do something
> like [self release] ?
>
> i feel stupid to ask this, but something shock me with [self release]...
> i know i can do this in the init method, when self is the class, but can it be
> done safely from the instance itself ???
_______________________________________________
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.


References: 
 >Re: [self release] question... (From: Philippe Mougin <email@hidden>)

  • Prev by Date: Re: [self release] question...
  • Next by Date: Programmatically Create Login Item
  • Previous by thread: Re: [self release] question...
  • Next by thread: how to get this type of regex matching happening (using AGRegex)?
  • Index(es):
    • Date
    • Thread