home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!jvnc.net!mitl.com!news
- From: edlau@mitl.com (Ed Lau)
- Newsgroups: comp.sys.next.programmer
- Subject: freeing an object--when?
- Message-ID: <1992Jul24.180535.18214@MITL.COM>
- Date: 24 Jul 92 18:05:35 GMT
- Sender: news@MITL.COM
- Distribution: na
- Organization: Matsushita Information Technology Laboratory
- Lines: 42
- Nntp-Posting-Host: chaos.mitl.com
-
-
-
- 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
-