PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Memory leak in PocketHAL

Hi Thierry,
I've just downloaded the trial version o Entrek Toolbox which detects memory leaks, have been trying on my apps.

The following code will leave a 52 byte (20 + 32 ie. 2 separate "new") memory leak:

Code:

oPHAL = PHAL::Display::Create(hwnd, p);
delete oPHAL;


Is this something I'm doing wrong?

Entrek's CodeSnitch also says that LoadLibrary had failed as part of creating the display:

Warning: API Failure(GetLastError()=126): LoadLibrary(0x00033820 ("CoreLinkLib.dll"))


[/code]
Here is the test code I was using:

Code:

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//register a default window class
WNDCLASS wc;
memset(&wc;, 0, sizeof(wc));

wc.lpfnWndProc = MainWindowProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszClassName = TEXT("TForm");
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
ATOM a = RegisterClass(&wc;);

HWND hwnd = CreateWindowEx
(
0, TEXT("TForm"), TEXT("aa"),
WS_VISIBLE

#ifdef WS_NONAVDONEBUTTON
| WS_NONAVDONEBUTTON //remove "smart minimize" button
#endif

,0, 0,
CW_USEDEFAULT, CW_USEDEFAULT,

NULL, 0, hInstance, 0
);

PHAL::DisplayParameters p;
p.m_orientation = PHAL::ORIENTATION_NORMAL;
p.m_swapEffect = PHAL::SWAP_DISCARD;

PHAL::Display *oPHAL = PHAL::Display::Create(hwnd, p);
delete oPHAL;

return 0;
}
The memory leak is definitely not normal. I must have overlooked something. On what device are you testing this?

As for the LoadLibrary(), that's perfectly normal. Don't worry about it.
It's on an ipaq 1940.
Already found one leak. I will make sure they all get fixed soon. For now, 52 bytes doesn't seem critical, considering that you only ever need to create one Display object.
No worries, I'm not too concerned about it as I've got quite a few other memory leaks in the app I'm testing that I've been sorting through anyhow :) Just thought I'd let you know.
Thierry, there also seems to be a resource leak or two when you start using surfaces. Calls to CreateCompatibleDC are not all getting freed. Man, this CodeSnitch is fantastic - it's picked up heaps of bugs that were so easy to miss.
Yes, the GDI Surface is the one I spotted right away. Where can I get my hands on this CodeSnitch tool?