discuss-gnustep
[Top][All Lists]
Advanced

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

Re: What does NSAutoreleasePool actually do?


From: Willem Rein Oudshoorn
Subject: Re: What does NSAutoreleasePool actually do?
Date: 19 Apr 2003 19:01:17 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

"黃俊傑(Chun-Chieh Huang)" <jjhuang@cm.nctu.edu.tw> writes:

> Dear all,
>     I have some questions about NSAutoreleasePool in GNUstep.
> 
>     I have written some code in OPENSTEP 4.2. I recalled that 
> NSAutoreleasePool is cleaned up when the command loop refreshes. 
> And I read dread.m and dwrite.m in GNUstep base source tarball.
> The two files, dread.m and dwrite.m, are all command line tools, which
> doesn't need GUI portion. So I think there should be no command loops
> in such a command line tool. But how come there is a NSAutoreleasePool
> instance? 

Because in dread.m the first line in the main method creates the 
autorelease pool:

 ...
  int
  main(int argc, char** argv)
  {
      NSAutoreleasePool *pool = [NSAutoreleasePool new];
      NSUserDefaults    *defs;
 ...

> 
> In my main.m, I created an NSAutoreleasePool, and create my simulator
> instance, set it up, and then make it peform some actions. Finally, I
> release my simulator instance and the pool.

This is the way most tools work.   
Additionally you might want to create and destroy additional release pools
in strategic places to avoid keeping objects alive till the tool exits.
This is especially important for tools that are supposed to run for
a long time.

> I need to modify some
> memory management, but it works. 

Hm, what do you mean with this.  Change where and why?  
Probably perfectly alright but I am just puzzled.


Wim Oudshoorn.




reply via email to

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