Freeing Container | developer.brewmp.com Freeing Container | developer.brewmp.com

Developer

Freeing Container

Hi,

I have a XY container, in which i have inserted a couple of widgets.

When I FREE the container pointer(memory), do i need to explicitly extract each of the widget from the container and FREE them( to prevent memory leak ), or they ar FREE'd implicitly.

Thanks in advance,
Sohan

Hi, Sohan
After freeing the container pointer , the widget pointer is still alive which could be the cause of memory leaks .Free the widget pointer explicitly.

Hi, Sohan
After freeing the container pointer , the widget pointer is still alive which could be the cause of memory leaks .Free the widget pointer explicitly.

When you insert a widget into a container, the container will AddRef() the widget. When the container is released, it will Release() all of its child widgets. So if you:

Create the widget (ref count will be 1)
Insert it in the container (ref count will be 2)
Release the widget (ref count will be 1 again)

When you release the container all of the child widgets will be released, their ref counts will go to 0, and they will free their memory.
-Erik

When you insert a widget into a container, the container will AddRef() the widget. When the container is released, it will Release() all of its child widgets. So if you:

Create the widget (ref count will be 1)
Insert it in the container (ref count will be 2)
Release the widget (ref count will be 1 again)

When you release the container all of the child widgets will be released, their ref counts will go to 0, and they will free their memory.
-Erik