Hello,
I've tested the following code on Windows mobile 5 phone emulator and
on real devices (HTC hermes and wizard); one process opens the picture
picker dialog (see the code) in loop and another process is closing
the window.

int _tmain(int argc, _TCHAR* argv[])
{
while (1){

OPENFILENAMEEX ofnex = {0};
ofnex.lStructSize = sizeof(ofnex);
ofnex.ExFlags = OFN_EXFLAG_THUMBNAILVIEW;
ofnex.lpstrFile = new TCHAR[MAX_PATH];
ofnex.nMaxFile = MAX_PATH;

GetOpenFileNameEx(&ofnex);

delete[] ofnex.lpstrFile;

}

return 0;
}

If I dump the global program memory (for 5 minutes for example), it
increases during time, as if there is a memory leak in this code. If I
don't call GetOpenFileNameEx but a fake modal window, there is no
memory increase....

Could someone correct my code or confirm what this?

Thanks for the help,

Jean-Christophe

RE: GetOpenFileNameEx memory leaks ? by RaduMotisan

RaduMotisan
Tue Apr 03 06:10:02 CDT 2007

Hello,

try it static first:

TCHAR szFile[MAX_PATH];

OPENFILENAMEEX ofnex = {0};
ofnex.lStructSize = sizeof(ofnex);
ofnex.ExFlags = OFN_EXFLAG_THUMBNAILVIEW;
ofnex.lpstrFile = szFile;
ofnex.nMaxFile = MAX_PATH;

GetOpenFileNameEx(&ofnex);

//use szFile ...

do you get the same memory leak?

--
Best regards,

Radu Motisan

http://www.teksoftco.com/forum
Windows Mobile Development Forum


"jeanchristophe.amiel@orange-ftgroup.com" wrote:

> Hello,
> I've tested the following code on Windows mobile 5 phone emulator and
> on real devices (HTC hermes and wizard); one process opens the picture
> picker dialog (see the code) in loop and another process is closing
> the window.
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> while (1){
>
> OPENFILENAMEEX ofnex = {0};
> ofnex.lStructSize = sizeof(ofnex);
> ofnex.ExFlags = OFN_EXFLAG_THUMBNAILVIEW;
> ofnex.lpstrFile = new TCHAR[MAX_PATH];
> ofnex.nMaxFile = MAX_PATH;
>
> GetOpenFileNameEx(&ofnex);
>
> delete[] ofnex.lpstrFile;
>
> }
>
> return 0;
> }
>
> If I dump the global program memory (for 5 minutes for example), it
> increases during time, as if there is a memory leak in this code. If I
> don't call GetOpenFileNameEx but a fake modal window, there is no
> memory increase....
>
> Could someone correct my code or confirm what this?
>
> Thanks for the help,
>
> Jean-Christophe
>
>

Re: GetOpenFileNameEx memory leaks ? by jeanchristophe

jeanchristophe
Wed Apr 04 07:36:17 CDT 2007

Hi,
Thank you very much for your help ;
I tried :

TCHAR szFile[MAX_PATH];
while (1){GetOpenFileNameEx(
}


Re: GetOpenFileNameEx memory leaks ? by jeanchristophe

jeanchristophe
Wed Apr 04 07:43:11 CDT 2007

Hi,
Thank you very much for your help :
I try :

TCHAR szFile[MAX_PATH];

while (1){
...
GetOpenFileNameEx
...
}

and also to put szFile as a global variable of the main program. In
both cases, the program memory keeps increasing. I also tried this
little main on a HP iPaq hw6910 windows mobile 5 device and there is
also a memory leak (not very surprising since it is also on wm5
emulators....)


Re: GetOpenFileNameEx memory leaks ? by Uncle

Uncle
Wed Apr 04 09:00:53 CDT 2007

In reply to jeanchristophe.amiel@orange-ftgroup.com
(jeanchristophe.amiel@orange-ftgroup.com) who wrote this in
1175513483.629802.219860@l77g2000hsb.googlegroups.com, I, Marvo, say :

Have you tried putting the OPENFILENAMEEX ofnex OUTSIDE the while loop, and
INSIDE the while loop memsetting it to zero? Does that make a difference?


> Hello,
> I've tested the following code on Windows mobile 5 phone emulator and
> on real devices (HTC hermes and wizard); one process opens the picture
> picker dialog (see the code) in loop and another process is closing
> the window.
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> while (1){
>
> OPENFILENAMEEX ofnex = {0};
> ofnex.lStructSize = sizeof(ofnex);
> ofnex.ExFlags = OFN_EXFLAG_THUMBNAILVIEW;
> ofnex.lpstrFile = new TCHAR[MAX_PATH];
> ofnex.nMaxFile = MAX_PATH;
>
> GetOpenFileNameEx(&ofnex);
>
> delete[] ofnex.lpstrFile;
>
> }
>
> return 0;
> }
>
> If I dump the global program memory (for 5 minutes for example), it
> increases during time, as if there is a memory leak in this code. If I
> don't call GetOpenFileNameEx but a fake modal window, there is no
> memory increase....
>
> Could someone correct my code or confirm what this?
>
> Thanks for the help,
>
> Jean-Christophe




Re: GetOpenFileNameEx memory leaks ? by Amiel

Amiel
Thu Apr 05 07:22:52 CDT 2007

Thank you for the reply,
I've put the OPENFILENAMEEX structure outside the loop (so, there is
just only one call to GetOpenFileNameEx), and the memory keeps
increasing. I've tested it on real devices and emulator and it does
not make differences . Here is the code of my two main, one to open
Picture chooser and one to close it and log memory. If I only start
the second main program (to dump memory), there is no leak. If I put a
message box instead of GetOpenFileNameEx , there is no leak.... Any
other idea ? My intention is to test it on smartphone 5 and crossbow.

First program to open picture chooser :

int _tmain(int argc, _TCHAR* argv[]){

TCHAR szFile[MAX_PATH];
OPENFILENAMEEX ofnex = {0};
ofnex.lStructSize = sizeof(ofnex);
ofnex.ExFlags = OFN_EXFLAG_THUMBNAILVIEW;
ofnex.lpstrFile = szFile;
ofnex.nMaxFile = MAX_PATH;

while (1){
GetOpenFileNameEx(&ofnex);
}

return 0;
}


Second program to close window and log memory:

int _tmain(int argc, _TCHAR* argv[]){

while (1){

//
// simulate mouse event
//
int x = 232; // for 240x... devices
int y = 10;

int x_max = GetSystemMetrics(SM_CXSCREEN);
int y_max = GetSystemMetrics(SM_CYSCREEN);
int x_norm = x * 65535 / x_max;
int y_norm = y * 65535 / y_max;

// click on the arrow if any
mouse_event(MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_ABSOLUTE, x_norm,
y_norm, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP + MOUSEEVENTF_ABSOLUTE, x_norm,
y_norm, 0, 0);

//
// wait 5 s
//
Sleep( 5000 );

//
// dump % of used program memory
//
MEMORYSTATUS info;
memset(&info, 0, sizeof(MEMORYSTATUS));

GlobalMemoryStatus(&info);

DWORD available = info.dwAvailPhys;
DWORD total = info.dwTotalPhys;
double percent = 100.0 - ((double)available*100.0/(double)total);

FILE *f = _wfopen(L"\\Temp\\log.txt", L"a");
if (f){
fwprintf( f, L"%d\t%d\t%.2f\r\n", total, available, percent);
fclose( f);
}

}
return 0;
}