home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5224 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  1.6 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!jvnc.net!mitl.com!news
  2. From: edlau@mitl.com (Ed Lau)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: freeing an object--when?
  5. Message-ID: <1992Jul24.180535.18214@MITL.COM>
  6. Date: 24 Jul 92 18:05:35 GMT
  7. Sender: news@MITL.COM
  8. Distribution: na
  9. Organization: Matsushita Information Technology Laboratory
  10. Lines: 42
  11. Nntp-Posting-Host: chaos.mitl.com
  12.  
  13.  
  14.     
  15. I am writing an application that loads a document from a file and displays it  
  16. in a window. My app has a controller object and document objects. Both  
  17. controller and document are instances of Object subclasses. Each document  
  18. instance has an outlet to its respective window and is the delegate for that  
  19. window.
  20.  
  21. Here's my problem: I want to free my document object when the user closes its  
  22. respective window. To do this, I have the following code in my windowWillClose:  
  23. method in Document.m:
  24.  
  25. - windowWillClose:sender
  26. {
  27.     [controller rmDoc:self];
  28.  
  29.     ...
  30. }
  31.  
  32. in my -rmDoc method in Controller.m, I do:
  33.  
  34. - rmDoc:aDoc
  35. {
  36.     // docList is a List containing my document objects    
  37.     [[docList removeObject:aDoc] free];
  38.  
  39.     ...
  40. }
  41.  
  42. However, since my document object is freed, its window is left without a  
  43. delegate. What to do?
  44.  
  45. I suppose I can have the controller be each window's delegate, but I prefer to  
  46. have each document be the delegate instead. The reason is mainly because each  
  47. window may have different max and min sizes--information the document instance  
  48. knows about.
  49.  
  50. What are possible solutions to this problem? Any suggestions appreciated. Thank  
  51. you in advance.
  52.  
  53. --Edward Lau
  54. edlau@chaos.mitl.com
  55.