Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!usc!elroy.jpl.nasa.gov!decwrl!pa.dec.com!shlump.nac.dec.com!bolt.enet.dec.com!minow From: minow@bolt.enet.dec.com (Martin Minow) Newsgroups: comp.sys.mac.programmer Subject: Re: RE: removing objects from THINK CList class Message-ID: <19302@shlump.nac.dec.com> Date: 23 Jan 91 00:44:25 GMT Sender: newsdaemon@shlump.nac.dec.com Organization: Digital Equipment Corporation Lines: 52 During the discussion of removing objects from a TCL list, I wrote that I had used a sequence like: > while ((myObject = myList->FirstItem()) != NULL) { > myList->Remove(myObject); > myObject->Dispose(); >} And a respondant quite naturally asked why I didn't use myList->DisposeItems(); Actually, the real situation was a set of multiply-connected lists that handle open PPC Toolbox sessions. The PPC class contains a list of open PPCPorts, the PPCPort class has a list of open sessions, and the PPCSession class has a list of active (asychronous) I/O buffers. Messages have an instance variable linking them to their Session and sessions have an instance variable pointing to their port. Looking only at the session-port interaction; the application terminates a session by mySession->Dispose(). This does the toolbox stuff, then executes itsPort->itsSessionList->Remove(), then does an inherited::Dispose(). If the application closes the port, it must empty the session list without using DoForEach or any method that uses that technique as the actual removal is done by the list element's Dispose() method. Here's the PPCPort disposal: void PPCPort::Dispose() { PPCSession *aSession; while ((aSession = (PPCSession *) itsSessions->FirstItem()) != NULL) aSession->Dispose(); itsSessions->Dispose(); /* Toolbox stuff deleted */ inherited::Dispose(); } Here's the PPCSession disposal: void PPCSession::Dispose() { /* Toolbox stuff deleted */ itsPort->itsSessions->Remove(this); inherited::Dispose(); } Hope this is clearer. Martin Minow minow@bolt.enet.dec.com