🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #390

Re: Destroying Zones

#390
From: Federico Heinz
Date: Sat, 01 Aug 1992 12:12
53 lines
2786 bytes
In article <1992Jul28.192006.21071@cubetech.com> andrew@cubetech.com (Andrew  
Loewenstern) writes:
> In article <1992Jul27.010436.1749@kakwa.ucs.ualberta.ca>  
gary@niagara.ucs.ualberta.ca (Gary Ritchie) writes:
> >I'm loading a nib file into its own zone, so that I can later destroy the  
> >zone and make everything go away.  I'm having a problem because the nib  
> >file contains Windows, and the program has a segmentation fault shortly  
> >after the zone is destroyed.
> >Could someone give me a quick summary on the steps necessary?
> 
> Make sure you orderOut and free all of the windows in the zone before
> destroying it or things will die. 
 
You'll have to do a bit more than that. There are plenty of situations in  
which the code snippet

	[[myWindow close] free];
	NXDestroyZone(windowZone);

will still cause a crash, albeit later, because the Appkit still has  
something to do with objects in the Window's View hierarchy. To solve that,  
you will need something along the following lines:

1) define a method -killZone: in your Application's delegate (or some other 
easy-to-find, steady object. The code for it is

- killZone:aZone
{
	NXDestroyZone((NXZone *)aZone);
	return self;
}

2) whenever you want to destroy the zone where you loaded a nib file, send  
the -free message to everything in sight, then invoke:

	[[NXApp delegate] perform:@selector(killZone:) with:(id)nibZone
		afterDelay:1 cancelPrevious:NO];

This arranges for the zone to be destroyed later, after the Appkit has  
completed processing for the current event and has long forgotten everything  
about you .nib section.

****** ALSO BEWARE OF NXImages!!!!!!! *******

If you have an NXImage in your .nib section/file, they will be loaded into  
the zone you specified. The problem is, the NXImage class keeps a list of the  
images you loaded, so you (and Button, for instance) can recall them with the  
+findImageNamed: message. If you destroy the zone, you will be deallocating  
the NXImages as well, and the image list points into never-ever-land. So if  
you are going to play tricks like these, keep in mind to load your icons  
separately from your .nib file. Otherwise, the second and subsequent  
instances you create from the .nib file will contain references to  
non-existent images, and will produce a crash.
Technical Details
Message-ID: <1992Aug1.121256.15796@heinz.in-berlin.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!math.fu-berlin.de!fub!heinz!federico
References: <1992Jul28.192006.21071@cubetech.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!math.fu-berlin.de!fub!heinz!federico
From: federico@heinz.in-berlin.de (Federico Heinz)
Subject: Re: Destroying Zones
Message-ID: <1992Aug1.121256.15796@heinz.in-berlin.de>
Sender: federico@heinz.in-berlin.de
Organization: Federico Heinz Consulting
References: <1992Jul28.192006.21071@cubetech.com>
Date: Sat, 1 Aug 1992 12:12:56 GMT
Lines: 54