[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What does NSAutoreleasePool actually do?
From: |
黃俊傑(Chun-Chieh Huang) |
Subject: |
Re: What does NSAutoreleasePool actually do? |
Date: |
20 Apr 2003 19:53:41 +0800 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Willem Rein Oudshoorn <woudshoo@xs4all.nl> writes:
> "黃俊傑(Chun-Chieh Huang)" <jjhuang@cm.nctu.edu.tw> writes:
[stuff deleted]
> 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;
> ...
Yes, I saw it before I post. Actually, I misunderstood the OpenStep
specification written in 1994. The manual said that NSAutoreleasePool
will be automatically handled in NSApplication, but I thought
NSAutoreleasePool is only concerned with NSApplication. I forgot that
many Foundation classes, such as NSArray, will be autoreleased. Sorry
I didn't express myself clear. And I know that NSAutoreleasePool is
used by many Foundation classes, not only ApplicationKit.
> >
> > 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.
Thanks for your suggestion. I'm working on it. Mini-tutorials from
Nicola Pero is a good starting point. I learned how to create nested
autorelease pools in these tutorials. I knew how to write programs in
OPENSTEP before, but I began to learn how it really works after porting
to GNUstep. :-)
> > 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.
Hm, sorry I didn't make myself clear. I mean I have to modify some
memory management method in my program. I knew little about memory
management in Objective-C until recently. I have to carefully examine
every step of memory alloc/release in my program, which was written on
OPENSTEP. Compared to C++/Java, there are really few resources for
Objective-C. I'm glad that I can continue to use Objective-C since
GNUstep was created. Maybe in the future, we can write applications once,
and execute the GNUstep application on UNIX/Win32/MacOS X, stably.
Best Regards,
Chun-Chieh
--
Chun-Chieh Huang(黃俊傑), or Albert | E-mail: jjhuang AT cm.nctu.edu.tw
|
Department of Computer Science |
National Tsing Hua University | MIME/ASCII/PDF/PostScript are welcome!
HsinChu, Taiwan | NO MS WORD DOC FILE, PLEASE!