Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_distroy_bitmap not freeing memory

This thread is locked; no one can reply to it. rss feed Print
al_distroy_bitmap not freeing memory
Thinkal VB
Member #16,859
May 2018

al_distroy_bitmap() is not freeing the resources;
Is it a problem of VS memory profiler or is it a problem with me debugging the wrong way or with the library.
Pics are attached to this post
Please need help .......

relpatseht
Member #5,034
September 2004
avatar

The debugger is showing how much memory is in use by your process. Calling al_destroy_bitmap will free memory to the memory manager, but the memory manager may not immediately free the memory back to the operating system. This is perfectly valid. Requesting resources from the operating system is an expensive operation (and in the case of memory, can be done a minimum of 4kb at a time). Thus, the memory manager maintains it's own pool of memory. This pool is used to make allocations of any size and keep OS requests to a minimum.

I.E. if you allocate 1kb, the memory manager will probably request 1mb from the OS and use that for future allocations your program makes. If the memory manager find it has a lot of free memory sitting around, it will return some back to the OS.

Thinkal VB
Member #16,859
May 2018

Thank you relpatseht
I guess OS and VStudio are better than me. That's good to hear. I was just frustrated seeing the memory not being deallocated. I thought I was leaking memory somewhere in the program. Once again thank you for your response.

relpatseht
Member #5,034
September 2004
avatar

It's definitely possible, but watching Visual Studio's resource monitor is not the best way to find memory leaks. You'd probably want your own memory manager for that.

For heap corruption on the other hand, the debug heap has some useful functionality: Gflags Heap Corruption Detection.

Thinkal VB
Member #16,859
May 2018

Thank you again relpatseht.....
I will look out for Heap corruptions.
Do you know how to load PNG images without alpha channel- for background textures? I guess textures don't need alpha channel - please correct me if I am wrong or need to know anything about this matter. Game assets are eating my RAM :-X

relpatseht
Member #5,034
September 2004
avatar

Once a texture had been uploaded to the GPU, there isn't much need for it to stick around in RAM (unless you intend to access it from the CPU for some reason). Usually, GPU drivers will keep a copy in RAM as backing store, so they can swap the texture out/back in if the GPU runs out of RAM. On the GPU, there is no such thing as a 3 channel texture. Most drivers allow you to upload a 3 channel image, but the alpha channel will be filled in on the GPU.

That said, are game assets really eating your RAM? How much RAM do you have? How much paging file space to you have? What is reasonable to assume your users will have? How much are your assets using? The last platform I developed for where 5MB was big was the original DS (which had 4MB of RAM total). Any modern PC will have more than 5MB of CPU cache. You can have a GB of assets alone loaded in RAM now and it wouldn't be a big deal.

Thinkal VB
Member #16,859
May 2018

Thanks again for the replay relpatseht....
I have 4GB of RAM on my computer. Chrome use some of it, then visual studio some of it. So I was being conservative. :P You know .....

Ah, I checked the heap allocation for memory leak and I found some.
But the weird thing is that the line number's it specified - I don't have any class or CPP file with that much code - can you demystify it. Pics are attached to the post.

Thank you once again for your enlightening informations

relpatseht
Member #5,034
September 2004
avatar

I think you forgot the attachment.

4GB of RAM doesn't mean the sum total of all programs have 4GB available, usually. By default, you'll have at least one paging file (whose size is managed by the operating system by default to vary size and increase up to about twice your RAM size) stored on your hard drive which the OS will move memory not currently being used.

IE: If chrome allocates 1GB of RAM, but most of the time is only using 100MB of that, and only accesses the other 900MB in rare occasions, the OS will move the 900MB to the paging file, so you have more hard RAM available for other applications.

keprast
Member #16,794
January 2018

Hey, man. How do you avoid "heap damage" :)
In addition, please pay attention to the characteristics of the heap memory.

Thinkal VB
Member #16,859
May 2018

Hai Relpatseht, thanks for your replay
Well, I think the upload didn't work well - however this time I will double check if it's uploaded well nice and clean.
Ah, I double and triple checked all the memory allocated using the heap operators new to make sure all the dynamically allocated variables are freed before the program hit's exit.
But I don't know much - I am here to take advice and guidance from bright and genius peoples like you... So please do share your thoughts on this too...

All of the code I wrote this far is attached to this post. I am a creepy coder - but pls do try to bear my bad coding style.

relpatseht
Member #5,034
September 2004
avatar

The output means allocations 471, 472, 473, and 474 are not being freed. They are 8, 40, 8, and 40 bytes long respectively.

I'd put a breakpoint in whatever the root allocation function is with a counter so it only fires on allocation 471 or higher. The callstack would then tell you the exact thing being allocated that isn't being freed.

Thinkal VB
Member #16,859
May 2018

Relpatseht .... Wow thanks
I will try that.

Go to: