Re: heap memory among shared libraries
Re: heap memory among shared libraries
- Subject: Re: heap memory among shared libraries
- From: Chris Kane <email@hidden>
- Date: Tue, 25 Sep 2001 15:33:37 -0700
On Tuesday, September 25, 2001, at 02:51 PM, Greg Titus wrote:
On Tuesday, September 25, 2001, at 02:32 PM, Jeff Howe wrote:
If I have two shared libraries, say, two frameworks used in
the same application, is it safe to malloc (or new) an object
in one framework, and free (or delete) it in the other one?
Yep, absolutely. (Assuming, of course, that the first framework isn't
_also_ going to try to free/delete the object later on. If so, you get
into the whole retain counting thing that Cocoa does.)
Each application has a single heap for dynamically allocated memory. It
doesn't matter where allocations and deallocations occur as far as
various libraries / frameworks / app code is concerned.
Well, as long as the memory is deleted with the same heap with which it
was allocated. Mac OS X, like Windows, allows for multiple heaps
(malloc_zone_t in Mac OS X). The Standard C library functions all use
the same heap, so there's no problem if you're using just those. Memory
you get from a library may not have come from the same heap, so should
either be freed with functions from the library, or the library should
tell you how to free it.
Chris Kane
Cocoa Frameworks, Apple