Developers Showcase: Garbage Collector

Memory management is a concern of many software developers, but it's not an obstacle Magento developers are burdened with. Magento developers Andrey Tserkus and Vladimir Pelipenko shared their perspective.

Andrey, what's so exciting about memory management in PHP?

"What's most exciting about it is actually the fact that there is none. If you've worked with other programming languages, then you know what a nightmare it is to track every new object you've created and new memory block allocated. As PHP-developers, we can use variables whenever we want to, we can drop objects at any point, and there is no limit on the number of arrays we can clone and create. We are fortunate to have an underlying language layer that takes care of memory management on its own. With PHP, you can stop worrying and begin programming!"

"There are some cases, though, when PHP developers should be concerned with memory script. If a script generates a large amount of reports, calls out to a lot of images, or transfers a large amount of data then it’s likely the script will exhaust all of its allocated memory - thus creating a fatal error. That's why PHP has a special resource manager to deal with it - the Garbage Collector."


Well, Vladimir, what is a Garbage Collector?

"The Garbage Collector is a tool that travels through allocated memory, checks the resources in use and returns unused resources back to the memory pool. It's not something developers control; it's invoked automatically when PHP finds that available resources are nearly depleted."

How does the Garbage Collector know that a variable or object is still in use?

"Each memory block in PHP has an internal counter called refcount. Whenever a variable links to that block, its refcount is incremented. When the link is broken, refcount is decremented. Memory blocks with a refcount equal to zero are not in use and may be safely returned to the memory pool."

When Magento developers are working on long-running tasks what should they do?

"When working on tasks with a long duration time, one should follow several coding practices. For example, to avoid memory leaks when processing a large amount of products, call the product’s clearInstance() method, once you've finished handling it. If you've made a custom module that sets objects inside products, clean these objects by overriding the product's core methods or observing events. In general, memory leaks are possible in any object or array. whenever you process a lot of data think about circular references and help the Garbage Collector by breaking them."


To further explore PHP memory management, and its impact on Magento, view the full article:

Back Older article Newer article

New theme released

Responsive Magento Theme - Gala Marcos

A truly impressive Magento template for fashion store from Galathemes, Gala Marcos. It amazes visitors by modern and high-fashion look, and also, neat design.

Read more

Our services


Magento Custom Development

Magento is the most powerful eCommerce system offering rich customization possibilities by extensions and modules.

We offer custom extension development performed by our full-time Magento experts to ensure the custom extension developed follow Magento code standard, optimized and pass our quality tests.

Read more


Magento Custom Design

Design and development a custom Magento template for your Magento store. Our designers and developers are specialists in Magento Commerce and have strong experience in Magento projects.

We provide all design in PSD files, template package and sample data. We also help you install the theme on your store if required. We start your project instantly and with highest priority.

Read more

Magento Template Conversion

PSD to Magento Theme Conversion

PSD to Magento Theme Conversion is a leading strength of us. We have an intelligent process and experienced staff, so you will save much time.

We easily convert a store designs in PSD format into a fully functional Magento commerce template. Quick and convenient for you to create an online store based on Magento is through "PSD to Magento Theme Conversion" service. We bring the flexibility, user friendly modules, and the extensions to improve the functionality of Magento.

Read more


Magento Site Development

We update our Magento knowledge everyday. Having an excellent knowledge on Magento design, Magento programming and server optimization, we guarantee your project get done perfectly.

We apply the philosophy of agile project management to ensure your project always performs on the right way, you'll get updates frequently, any changes of scope of project can be informed early to minimize risks, time and cost.

Read more


Magento Server Optimization

We realy provide the best service for you. Among them are optimized for Magento server is very important. Your ecommerce shop will flexibility and agility absolute. Connecting with customers, processing speed, the gentle query and sensitive to the search engine is very easy

Read more