🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.programmer
3 messages
3 total messages Started by Ed Lau Fri, 24 Jul 1992 18:05
freeing an object--when?
#226
Author: Ed Lau
Date: Fri, 24 Jul 1992 18:05
42 lines
1658 bytes
	
I am writing an application that loads a document from a file and displays it  
in a window. My app has a controller object and document objects. Both  
controller and document are instances of Object subclasses. Each document  
instance has an outlet to its respective window and is the delegate for that  
window.

Here's my problem: I want to free my document object when the user closes its  
respective window. To do this, I have the following code in my windowWillClose:  
method in Document.m:

- windowWillClose:sender
{
    [controller rmDoc:self];

	...
}

in my -rmDoc method in Controller.m, I do:

- rmDoc:aDoc
{
    // docList is a List containing my document objects	
    [[docList removeObject:aDoc] free];

	...
}

However, since my document object is freed, its window is left without a  
delegate. What to do?

I suppose I can have the controller be each window's delegate, but I prefer to  
have each document be the delegate instead. The reason is mainly because each  
window may have different max and min sizes--information the document instance  
knows about.

What are possible solutions to this problem? Any suggestions appreciated. Thank  
you in advance.

--Edward Lau
edlau@chaos.mitl.com
Re: freeing an object--when?
#243
Author: Illan Colombick
Date: Sun, 26 Jul 1992 13:18
40 lines
1597 bytes
In article <1992Jul24.180535.18214@MITL.COM> edlau@mitl.com (Ed Lau) writes:



>Here's my problem: I want to free my document object when the user closes its  
>respective window. To do this, I have the following code in my windowWillClose:  
>method in Document.m:

>- windowWillClose:sender
>{
>    [controller rmDoc:self];

>        ...
>}

[stuff deleted]

>However, since my document object is freed, its window is left without a  
>delegate. What to do?

>--Edward Lau
>edlau@chaos.mitl.com

Surely it does not matter that the window is without a delegate? The Window 
is about to close. Unless you have setFreeOnClose: NO (default is YES), so 
that the window just disappears from the screen, but remains in existence. 
In that case, have windowWillClose check  the dontFreeOnClose value to 
decide whether or not to free the Document. 

If I have missed something here about doomed delegateless windows, please do 
tell me, I am (very) far from being an expert NeXT programmer.

Bye.
Illan

   ......
  \\\\\///
  C o l o     {textmail, NeXTmail} to colo@{odie, TuRInG}.ee.wits.ac.za
   %% - %
    ~%%%~
Re: freeing an object--when?
#292
Author: mkrogers
Date: Tue, 28 Jul 1992 19:31
25 lines
1754 bytes
In article <colo.21@odie.ee.wits.ac.za>, colo@odie.ee.wits.ac.za (Illan Colombick) writes:
> In article <1992Jul24.180535.18214@MITL.COM> edlau@mitl.com (Ed Lau) writes:
> 
> [stuff deleted]
> 
>>However, since my document object is freed, its window is left without a  
>>delegate. What to do?
> 
> Surely it does not matter that the window is without a delegate? The Window 
> is about to close. Unless you have setFreeOnClose: NO (default is YES), so 
> that the window just disappears from the screen, but remains in existence. 
> In that case, have windowWillClose check  the dontFreeOnClose value to 
> decide whether or not to free the Document. 

There might be a problem if the window thinks that the freed object is
still its delegate and tries to send it a message.  I would guess that
after the windowWillClose: method returns the window is done with
its delegate.  If you want to be on the safe side you could set
the window's delegate to nil in windowWillClose:, or use
	[NXApp delayedFree:self];
in the windowWillClose: method to free your document.  The document
will be freed just before NXApp tries to get the next event.

	-mike
	mkr@cs.amherst.edu
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads