I often search for different things on internet so I have written a small utility that makes the searching of google.com much easier. The program consists of a small edit box that pops up when you press Win+G, and when you press enter, the window dissappears and the text typed in the edit box is being sent to google. This means that you don't have to open a browser and go to www.google.com everytime you want to search for something.

When you finish typing and press enter, the text goes to a buffer called 'buffer2'. After that all spaces are converted to plus signs and all special characters are converted to their representing hex value, eg. "!" would become "%21". The resulting string is stored in 'buffer'.

After that 'buffer' is append to "http://www.google.com/search?hl=sv&q=" and is then shellexecuted.

My problem is that the program occupies an enourmous amount of memory and every time I make a new search, the reserved memory increases! Directly after startup the ram usage is 2268kb. Ten searches later it's 4108kb! Why? Can someone please help me with this. I have attached the source (RadASM)

Posted on 2002-09-04 08:20:11 by Delight
use Virtual/LocalAlloc for the memory bufers and release them when you're done (if you're not doing this already)... can't check the code since I'm at work and can't check the file attachment... blah... work sucks... but that ill hopefully help a bit...
Posted on 2002-09-04 09:03:31 by NervGaz
He's using .data? section buffers, NervGaz. Even safer than VirtualAlloc in terms of memory leaks.

I believe ShellExecute has a memory leak on some systems. Try commenting out that line and see if memory usage still goes up. If not, it's gotta be something else...
Posted on 2002-09-04 09:08:56 by Qweerdy
ok, my bad then I guess
Posted on 2002-09-04 09:10:14 by NervGaz

you must call DeleteObject after you have used the brush

i say create one brush save the vaule.. and pass it each WM_CTLCOLOREDIT
dont forget to DeleteObject,yourbrush in WM_CLOSE

or call in the begining of WM_CTLCOLOREDIT to DeleteObject and delete you brush
and create new one ..

i wanted to ask you

;for what this code. and xor eax,eax changes the zero flag
.elseif eax==WM_COMMAND

cmp wParam,IDCANCEL
xor eax,eax
jne @F
inc eax


very nice idea :alright:

two suggestions :
1. make a way to close the program
2. open google in new window
Posted on 2002-09-04 10:39:37 by eko
You can try this :

.elseif eax==WM_INITDIALOG
invoke GetCurrentProcess <--- new
invoke SetProcessWorkingSetSize,eax,-1,-1 <--- new

invoke RegisterHotKey,hWin,0DEADBEEFh,MOD_WIN,VK_G


invoke wsprintf,offset buffer2,offset google ,offset buffer ;buffer2 = google + buffer
invoke ShellExecute,hWnd,offset open,offset buffer2,0,0,SW_SHOWNORMAL;go
mov wParam,0
invoke GetCurrentProcess <--- new
invoke SetProcessWorkingSetSize,eax,-1,-1 <--- new


PS Cool program
Posted on 2002-09-04 12:30:10 by WinCC
Hi everybody! Thanks for your replies!

Eko, thanks for pointing that out. I did not think about the brush and I guess that contributed to the ram occupation, but I'm getting some strange result now. Instead of starting at 2mb and slowly increase up to 4mb, it now goes from 2 to 4mb after just one search! Strange! I don't remember what the code you were wondering about is doing, and if xor set the zeroflag, it doesn't work anyway :rolleyes: About your suggestions. I want the program to be in autostart and therefore it's not necessary to add a close button or so. It's still possible to close it using ALT+F4 though. If you use Shift+enter, google will open in a new window. This is nothing I have added, I guess windows has it built in already (atleast WinXP has)!

Qweerdy, you were right about shellexcute having a memory leek. After commenting that line, the used memory was stable around 2mb. The question now is how I can replace shellexexute...

WinCC, I thought about that too, but I believe thoose APIs are win2000/XP/NT compatible only :(
Posted on 2002-09-04 13:48:04 by Delight
I have tried ShellExecute, ShellExecuteEx and WinExec (didn't even work), but nothing works satisfactory. The only solution I can think of is run an external program (using CreateProcess) that executes the string recieved by the commandline. This would probably work but it feels so dirty! Does anyone know a better way?

Posted on 2002-09-04 14:52:13 by Delight
Well I am using windows 2k with sp3 and been using your program for about 3 hours. So far it sits at 2mbs. Nice little program though.

Posted on 2002-09-04 21:11:07 by Betrayed
Set the image flag IMAGE_FILE_AGGRESSIVE_WS_TRIM at link time using the switch "/WS:AGGRESSIVE". This will hopefuly? cause windows to activly page your processes memory into the swap file.

Also the reason for the sudden increase in memory the first time a search is performed is because windows loads about 8 new dll modules into your process when the ShellExecute API is first called.
Posted on 2002-09-04 22:48:02 by huh
Thanks for your help guys!
huh, just after startup the process had 10 dlls loaded, after ShellExecute it was 30 :grin: ! I tried the link parameter but I didn't notice any difference.
Posted on 2002-09-05 05:06:27 by Delight