O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Memory Ownership Issues

One of the difficulties involved when using dynamic memory is determining who is responsible for freeing a piece of allocated memory when nobody else is using it. This is known as memory ownership. There are many different solutions to this problem, each with their own tradeoffs and benefits, as witnessed by Java and Cocoa garbage collection, C++ RAII (resource acquisition is initialization), and Cocoa’s reference counting.

There are no uniform rules for memory ownership for Unix and C library calls, so you pretty much need to check the manpage for the calls in question (which is usually a good idea anyway). For instance:

  • getenv() returns a char *, but you do not need to free it since the environment variables are all ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required