Re: Memory problem
- From: Michael Ash <mike@xxxxxxxxxxx>
- Date: Fri, 16 Sep 2005 04:31:52 -0500
xcommerx <xcommerx.1vfaxg@xxxxxxxxxxxxxxxxxxx> wrote:
>
> I test the memory usage with my System Resources Manager and the top
> command (I work with Linux but the Mac forums are the only place to go
> to with Objective-C questions).
Well, there's your error.
There are two levels of memory allocation going on here, even though you
the programmer normally only sees one of them.
One level is the malloc level, where you can request things in byte-sized
chunks (or actually, on OS X, 16-byte-sized chunks, probably similar on
Linux). At a lower level, malloc is getting memory from the OS in
page-sized chunks, which is 4kB on OS X and most other OSes.
Things like fragmentation can prevent malloc from giving those pages back
to the OS. If you allocate enough objects to fill a 4kB page and then
destroy all but one of them, that page has to stay mapped into your
process. But the good news is that the page can be reused to allocate more
objects, so this isn't a big deal.
Malloc will also hang on to the page even if it's empty, a lot of the
time, because allocating and deallocating a page is expensive. Chances are
that your program is going to need to allocate more memory soon, and so it
won't give it up right away.
To summarize: looking at your program's memory usage by using top or
similar tools looks at its usage at the system (page) level, and will be
extremely misleading when you're worrying about usage at the user (object)
level.
I don't know what's available on Linux, but on the Mac I would use tools
such as ObjectAlloc, MallocDebug, 'leaks', etc. to discover whether I was
leaking any objects. I'm sure similar things exist in the Linux world, you
just need to find the right tool for the job.
--
Michael Ash
Rogue Amoeba Software
.
- References:
- Memory problem
- From: xcommerx
- Re: Memory problem
- From: Gregory Weston
- Re: Memory problem
- From: xcommerx
- Re: Memory problem
- From: Gregory Weston
- Re: Memory problem
- From: Ben Golding
- Re: Memory problem
- From: xcommerx
- Memory problem
- Prev by Date: Re: Need help to decide how to do project
- Next by Date: Re: ER Diagram tool
- Previous by thread: Re: Memory problem
- Next by thread: No menubar for Java app from custom launcher
- Index(es):
Relevant Pages
|
Loading