Core Foundation: 2 Useful Memory Management Functions

Petros Demetrakopoulos
Mar 18 · 2 min read

As Apple’s documentation states:

Core Foundation is a framework that provides fundamental software services useful to application services, application environments, and to applications themselves.

Photo by Carlos Irineu da Costa on Unsplash

One of the extremely useful features that Core Foundation offers, is a group of functions that provide us with detailed information regarding the memory state of a Core Foundation object (an instance of a Class).

The first memory-related function of Core Foundation is CFGetRetainCount and it returns the retain count of the object. This function takes a single argument that is the object that we want to get the retain count for.

An example is shown below:

Line 9 will print the retain count of the object myCar (in this case the retain count is 2). This function can be very useful when we want to debug or we suspect possible retain cycles and memory leaks.

The second useful memory management function of Core Foundation framework is CFGetAllocator . This function returns the allocator used to allocate the given instance. This function can be very useful when we want to use the same allocator in order to allocate a new object.

An example is shown below:

Line 9 will print the CFAllocator that allocated the given object. This function returns an optional allocator and its memory address, thus we know exactly where an instance is stored.

That’s all folks!

Thanks for your time! I hope you enjoyed it.

Geek Culture

Proud to geek out.

Sign up for Geek Culture Hits

By Geek Culture

Subscribe to receive top 10 most read stories of Geek Culture — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Petros Demetrakopoulos

Written by

💻Code-blooded, 🌏 Traveler ⌨️ Computer Science graduate, AUEB alumnus. Passionate Homebrewer🍺. Lifelong learner 📚.

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Petros Demetrakopoulos

Written by

💻Code-blooded, 🌏 Traveler ⌨️ Computer Science graduate, AUEB alumnus. Passionate Homebrewer🍺. Lifelong learner 📚.

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store