Re: heap memory among shared libraries
Re: heap memory among shared libraries
- Subject: Re: heap memory among shared libraries
- From: Greg Titus <email@hidden>
- Date: Tue, 25 Sep 2001 14:51:33 -0700
On Tuesday, September 25, 2001, at 02:32 PM, Jeff Howe wrote:
I am not sure if this is the proper group in which to ask
this question, but I'll try it here:
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.
Also different from Classic MacOS, this heap is visible only to that
single application (that whole protected memory thing...) and is
automatically destroyed when the application exits, reclaiming all
memory. (It has been interesting seeing some of the questions on this
list - presumably from former classic programmers - trying to manually
clean things up before the application exits. I am _so_ happy not to
have had to deal with things like that.)
Hope this helps,
--Greg