PDA

View Full Version : Memory leak with event handler


bnichols
07-29-2002, 11:16 AM
Hello, I'm new to Brew, so I hope I don't make too much of an idiot of myself.

I'm just playing around with the IImage display and what I thought is a very simple piece of code, turns out to leak memory faster than Ronald Reagan. The code just puts a bitmap on the screen and then updates the screen with any keypress. It does nothing else. Please let me know what I'm doing wrong.

Thanks,
Ben

Code:

static boolean ResApp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
AEERect rc;
AECHAR szBuf[30] = {0};

CResApp * pMe = (CResApp*)pi;

switch (eCode)
{
case EVT_APP_START: // Applet start event
case EVT_APP_RESUME:
IDISPLAY_ClearScreen (pMe->a.m_pIDisplay); // Erase whole screen
IIMAGE_SetDrawSize(pMe->m_pIImage, CROWDWIDTH, CROWDHEIGHT);
IIMAGE_Draw(pMe->m_pIImage, pMe->m_nX, pMe->m_nY);
IDISPLAY_Update(pMe->a.m_pIDisplay);
return TRUE;
case EVT_KEY_PRESS: // process key-down event
IDISPLAY_ClearScreen (pMe->a.m_pIDisplay); // Erase whole screen
IIMAGE_SetDrawSize(pMe->m_pIImage, CROWDWIDTH, CROWDHEIGHT);
IIMAGE_Draw(pMe->m_pIImage, pMe->m_nX, pMe->m_nY);
IDISPLAY_Update(pMe->a.m_pIDisplay);
return TRUE;
case EVT_APP_STOP:
return TRUE;
case EVT_APP_SUSPEND:
return TRUE;
default:
break;
}

return FALSE;
}

smarkwell
07-29-2002, 11:39 AM
Make sure you free the image information when you are done.

I'm assuming that you have an IImage inside CResApp, well make sure you call FREE on the image when the program exits.

bnichols
07-29-2002, 11:47 AM
I am freeing the memory on exit, but that's not really the problem anyway. What happens is, every time I hit a key, the available memory decreases until it's gone and then the app crashes. I'm not really allocating anything each iteration, so this behavior seems quite odd.

Kevin
07-30-2002, 11:17 AM
I would have to see more of your code. Where does pMe->m_pIImage get assigned/released?

arunbangari
07-30-2002, 10:14 PM
Hi,
How did you load the image?Although you may not be allocating anything, but it could happen that BREW API's that you are using allocating memory?More code would be helpful...

Regards
Arun Bangari