RE: SHNotificationAdd produces a memory leak by ashleyel
ashleyel
Fri Oct 31 14:52:27 CST 2003
------=_NextPart_0001_05432708
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
You may have to destroy the GDI object with DestroyIcon call. Load the icon
only once and use the same handle in all the calls.
Ashley Antony Elenjickal
Devp Support - Windows Embedded
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Doron" <doron@_please_remove__orsus.com>
Sender: "Doron" <doron@_please_remove__orsus.com>
Subject: SHNotificationAdd produces a memory leak
Date: Wed, 29 Oct 2003 07:48:17 -0800
Lines: 85
Message-ID: <06f701c39e34$11d781d0$a001280a@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOeNBHXBOjpl0x/TzuWkRsJH+ErJg==
Newsgroups: microsoft.public.pocketpc.developer
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.pocketpc.developer:63434
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.pocketpc.developer
Recreation steps:
Calling the SHNotificationAdd and then the remove a number
of times results in a memory buildup in the gwes.exe
process.
Running the attached code causes a memory buildup of
~200K. This memory is never recovered until the device
resets.
The code was executed in the debug compilation, but not in
debug mode.
Hardware:
iPaq 3950, Pocket PC 2002. SanDisk Wireless card.
<CODE>
// CheckBSTR.cpp : Defines the entry point for the
application.
//
#include "stdafx.h"
#include <comdef.h>
#include "notify.h"
#include "resource.h"
#define IDS_DEFAULTHTMLMESSAGE TEXT("<html><body><form
method=\"POST\" action=><p>This is an <font
color=\"#0000FF\"><b>HTML</b></font> notification stored
in a <font color=\"#FF0000\"><i>string</i></font> table!
</p><p align=right><input type=button name='cmd:10'
value='Ok'> <input type=button name='cmd:2'
value='Cancel'></p></body></html>");
#define IDS_DEFAULTTITLE TEXT("Sample
Notification...")
static const GUID guidNotifyApp =
{ 0x85ee47b2, 0x57d7, 0xEEFE, { 0x8e, 0x7a, 0x36, 0x48,
0x4, 0x43, 0xd0, 0x62 } };
HINSTANCE g_hInst;
int g_iIDCounter = 0;
void InternalNotification();
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE
hPrevInstance,
LPTSTR
lpCmdLine,
int nCmdShow)
{
g_hInst = hInstance;
for(int i = 0; i < 400; i++)
{
InternalNotification();
}
return 0;
}
void InternalNotification()
{
HICON hIcon = (HICON)LoadImage (g_hInst,
MAKEINTRESOURCE(IDI_MESSAGE),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
SHNOTIFICATIONDATA* pCurrentNotification =
(SHNOTIFICATIONDATA*)malloc( sizeof(SHNOTIFICATIONDATA));
pCurrentNotification->dwID = g_iIDCounter;
pCurrentNotification->clsid = guidNotifyApp;
pCurrentNotification->npPriority = SHNP_INFORM;
pCurrentNotification->csDuration = 0;
pCurrentNotification->hwndSink = 0;
pCurrentNotification->pszHTML =
IDS_DEFAULTHTMLMESSAGE;
pCurrentNotification->hicon = hIcon;
pCurrentNotification->cbStruct = sizeof
(SHNOTIFICATIONDATA);
pCurrentNotification->pszTitle = IDS_DEFAULTTITLE;
pCurrentNotification->grfFlags = NULL;
SHNotificationAdd(pCurrentNotification);
Sleep(2000);
SHNotificationRemove(&guidNotifyApp, g_iIDCounter);
free(pCurrentNotification);
}
</CODE>
------=_NextPart_0001_05432708
Content-Type: text/x-rtf
Content-Transfer-Encoding: 7bit
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 You may have to destroy the GDI object with DestroyIcon call. Load the icon only once and use the same handle in all the calls.
\par
\par Ashley Antony Elenjickal
\par Devp Support - Windows Embedded
\par Microsoft Corporation
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par \pard\li720 --------------------
\par Content-Class: urn:content-classes:message
\par From: "Doron" <doron@_please_remove__orsus.com>
\par Sender: "Doron" <doron@_please_remove__orsus.com>
\par Subject: SHNotificationAdd produces a memory leak
\par Date: Wed, 29 Oct 2003 07:48:17 -0800
\par Lines: 85
\par Message-ID: <06f701c39e34$11d781d0$a001280a@phx.gbl>
\par MIME-Version: 1.0
\par Content-Type: text/plain;
\par \tab charset="iso-8859-1"
\par Content-Transfer-Encoding: 7bit
\par X-Newsreader: Microsoft CDO for Windows 2000
\par X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
\par Thread-Index: AcOeNBHXBOjpl0x/TzuWkRsJH+ErJg==
\par Newsgroups: microsoft.public.pocketpc.developer
\par Path: cpmsftngxa06.phx.gbl
\par Xref: cpmsftngxa06.phx.gbl microsoft.public.pocketpc.developer:63434
\par NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
\par X-Tomcat-NG: microsoft.public.pocketpc.developer
\par
\par Recreation steps:
\par Calling the SHNotificationAdd and then the remove a number
\par of times results in a memory buildup in the gwes.exe
\par process.
\par Running the attached code causes a memory buildup of
\par ~200K. This memory is never recovered until the device
\par resets.
\par The code was executed in the debug compilation, but not in
\par debug mode.
\par
\par Hardware:
\par iPaq 3950, Pocket PC 2002. SanDisk Wireless card.
\par
\par <CODE>
\par // CheckBSTR.cpp : Defines the entry point for the
\par application.
\par //
\par
\par #include "stdafx.h"
\par #include <comdef.h>
\par #include "notify.h"
\par #include "resource.h"
\par
\par #define IDS_DEFAULTHTMLMESSAGE\tab TEXT("<html><body><form
\par method=\\"POST\\" action=><p>This is an <font
\par color=\\"#0000FF\\"><b>HTML</b></font> notification stored
\par in a <font color=\\"#FF0000\\"><i>string</i></font> table!
\par </p><p align=right><input type=button name='cmd:10'
\par value='Ok'> <input type=button name='cmd:2'
\par value='Cancel'></p></body></html>");
\par #define IDS_DEFAULTTITLE\tab\tab TEXT("Sample
\par Notification...")
\par
\par static const GUID guidNotifyApp =
\par \{ 0x85ee47b2, 0x57d7, 0xEEFE, \{ 0x8e, 0x7a, 0x36, 0x48,
\par 0x4, 0x43, 0xd0, 0x62 \} \};
\par
\par HINSTANCE g_hInst;
\par int g_iIDCounter = 0;
\par
\par void InternalNotification();
\par
\par
\par int WINAPI WinMain(\tab HINSTANCE hInstance,
\par \tab\tab\tab\tab\tab HINSTANCE
\par hPrevInstance,
\par \tab\tab\tab\tab\tab LPTSTR
\par lpCmdLine,
\par \tab\tab\tab\tab\tab int nCmdShow)
\par \{
\par \tab g_hInst = hInstance;
\par \tab for(int i = 0; i < 400; i++)
\par \tab\{
\par \tab\tab InternalNotification();
\par \tab\}
\par \tab return 0;
\par \}
\par
\par
\par void InternalNotification()
\par \{
\par \tab HICON hIcon = (HICON)LoadImage (g_hInst,
\par MAKEINTRESOURCE(IDI_MESSAGE),
\par \tab\tab IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\par \tab SHNOTIFICATIONDATA* pCurrentNotification =
\par (SHNOTIFICATIONDATA*)malloc( sizeof(SHNOTIFICATIONDATA));
\par \tab pCurrentNotification->dwID = g_iIDCounter;
\par \tab pCurrentNotification->clsid = guidNotifyApp;
\par \tab pCurrentNotification->npPriority = SHNP_INFORM;
\par \tab pCurrentNotification->csDuration = 0;
\par \tab pCurrentNotification->hwndSink = 0;
\par \tab pCurrentNotification->pszHTML =
\par IDS_DEFAULTHTMLMESSAGE;
\par \tab pCurrentNotification->hicon = hIcon;
\par \tab pCurrentNotification->cbStruct = sizeof
\par (SHNOTIFICATIONDATA);
\par \tab pCurrentNotification->pszTitle = IDS_DEFAULTTITLE;
\par \tab pCurrentNotification->grfFlags = NULL;
\par \tab SHNotificationAdd(pCurrentNotification);
\par \tab Sleep(2000);
\par \tab SHNotificationRemove(&guidNotifyApp, g_iIDCounter);
\par \tab free(pCurrentNotification);
\par
\par \}
\par </CODE>
\par \pard
\par
\par }
------=_NextPart_0001_05432708--