Reputation: 1
I have been trying to use screenshots stored in a HBITMAP and outputting this stored as a PNG image.
However, the code appears to have a memory leak in it, as memory does not appear to be freed up correctly.
void saveAsPNG(HBITMAP h)
{
CImage image;
if(_access(location, 0) == 0)
{
unlink(location); //Delete the image if currently exists
}
image.Attach(h);
image.Save(location,Gdiplus::ImageFormatPNG);
h = image.Detach();
image.Destroy();
image.ReleaseGDIPlus();
}
This code works, but clearing up memory does not seem to happen. According to the private memory set column in Task Manager, image.Destroy does not affect the memory at all, whilst image.ReleaseGDIPlus appears to clean up some data. The HBITMAP comes from a previous function and is GlobalFreed at a later point in the code seperate to this function.
Is there a line missing?
Upvotes: 0
Views: 997