discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

POC destructors? (was Re: bogus retain via NSEnumerator)


From: Ben Golding
Subject: POC destructors? (was Re: bogus retain via NSEnumerator)
Date: Fri, 23 Apr 2004 16:45:56 +1000
User-agent: MT-NewsWatcher/3.4 (PPC Mac OS X)

In article <4088AA4F.DDE8A533@nospam.idiom.com>,
 "John C. Randolph" <jcr@nospam.idiom.com> wrote:

> Of course not.  I balance my retains and releases, I use -release when I
> want to get rid of something immediately, and I use autorelease when
> something else might want to keep the object in question around.  In
> other words, I follow the published rules for retain/release.

This discussion left me wondering how you can be sure when a program 
using garbage collection can know when an object is finally released.  

If I have a class that opens a file in it's init method, like:

   @implementation MyFile

   - (id)initWithPath:(char *)path
   {
      if ((self = [super init]) == nil)
         return nil;

      _fp = fopen(path, "r");

      return self;
   }

   - (void)dealloc
   {
      fclose(_fp);
      [super dealloc];
   }
  
   @end

How can I know when the -dealloc method is called by the garbage 
collector?  If I create a lot of files using my class, how can I get POC 
to call the destructor so I don't run out of file descriptors?

I had a look at the POC documentation and I couldn't see any 
documentation on what conditions a destructor is called, or even if 
there is a destructor method that's invoked when an object is destroyed.

One advantage of the autorelease pool mechanism is that when I send a 
-release message to an object and there are no other references, I know 
that its -dealloc method will be called then and there.  There are 
occasions when I want to defer the release of the objects because it 
could impact the UI experience in which case I use -autorelease.  The 
simple control that gives is quite something.

So is there a way to force an object to call a destructor in POC or are 
you at the dependent on the garbage collector?

   Ben.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]