(yes,my english is terrible,but i hope,you understand it)
hm,i played around with win2k's task-manager and see,that there is a memory leak in my program (a german-english dictionary *g*) - if i searched for some words,the memory size grows up until 23000 KB ... i tested my code with memproof, but there were any leaks. Then, i look into my extract_code_part (to extract and filter the words) an there i have had two LOCAL variables

Extr_und_add proc uses ebx eax edx esi edi ecx lpSource:DWORD, lpPos:DWORD
;Gr??en usw
MAX_BUFF equ 1024
LEER_ZEICHEN equ 20

LOCAL deutsch_buff
LOCAL englisch_buff

mov esi,lpSource
add esi,lpPos
...


i replaced them to:

Extr_und_add proc uses ebx eax edx esi edi ecx lpSource:DWORD, lpPos:DWORD
;Gr??en usw
MAX_BUFF equ 1024
LEER_ZEICHEN equ 20

.data
deutsch_buff db(MAX_BUFF) dup(0)
englisch_buff db(MAX_BUFF) dup(0)

.code
mov esi,lpSource
add esi,lpPos


and tested with task-manager again
now is the memory size about 6500 KB (when i search for something ,else about 400KB).
Is it Win2k or a compiler bug?
Posted on 2003-01-16 14:20:27 by CDW
dunno exactly what the problem is, but there's a lot of things to consider.
First, the second proc will not be re-entrant/multi-threadable, as it only
has one pair of buffers. second, does the program leak more and more
when you run the proc multiple times, or is a fixed "leak"?
Posted on 2003-01-16 14:37:12 by f0dder
2. the proc leaks more and more...

1. Ok: the searchProc calls the Extr_und_add...
SearchProc is a thread, but its a single thread, if the user push the search button again, i first kill this thread :)
so it is not multithreadable




Extr_und_add proc uses ebx eax edx esi edi ecx lpSource:DWORD, lpPos:DWORD
;Gr??en usw
MAX_BUFF equ 1024
LEER_ZEICHEN equ 20

.data
deutsch_buff db(MAX_BUFF) dup(0) ;now i have this
englisch_buff db(MAX_BUFF) dup(0)
;old version (with leak in memory) had LOCAL

.code
mov esi,lpSource
add esi,lpPos
mov edx,esi ;die momentane position festhalten
mov ah,0Ah

;FILTERN
.if filter.begriff_am_anfang!=0
dec esi

.if BYTE PTR[esi]!=0Ah && BYTE PTR[esi]!=20h

ret
.endif
inc esi
.endif
;FILTERNENDE
mov ecx,lpSource
SUCHE_ANFANG_LOOP:
cmp ecx,esi
je OUT1 ;f?r den unwahrscheinlichen Fall,dass unser Begriff in der
dec esi ;ersten Zeile steht - damit es keine Speicherverletzung gibt
mov al,BYTE PTR[esi]
cmp al,ah
jne SUCHE_ANFANG_LOOP
sub edx,esi ;wieviele Zeichen unteschied zwischen Wortpos und Anfang?
OUT1:
.if vorherige_zeile==esi
ret
.endif

mov vorherige_zeile,esi




.if filter.english!=0
lea edi,deutsch_buff

mov ecx,LEER_ZEICHEN+1
mov al,20h
FILL_LOOP:
dec ecx
mov BYTE PTR[edi+ecx],al

jnz FILL_LOOP
add edi,LEER_ZEICHEN

.else
lea edi,deutsch_buff
dec edi
.endif
xor ecx,ecx
mov ah,3Ah


KOPIERE_DEUTSCH_LOOP:
inc ecx
mov al, BYTE PTR[esi+ecx]
cmp ah,al
je VORCHECK
END_CHECK:
mov BYTE PTR[edi+ecx],al
jmp KOPIERE_DEUTSCH_LOOP

VORCHECK:
cmp ah,BYTE PTR[esi+ecx+1]
jne END_CHECK



WEITER1:
.if (filter.nur_eine_sprache!=0)
.if (filter.english!=0)
.if ecx>edx
ret
.endif
.else
.if ecx<edx
ret
.endif
.endif
.endif




mov BYTE PTR[edi+ecx],0 ;abschlie?en
inc ecx
add esi,ecx
mov ebx,ecx ;stringl?ngemitz?hlen

.if ebx>zeilen_laenge
mov zeilen_laenge,ebx
.endif


.if filter.english==0
lea edi,englisch_buff

mov ecx,LEER_ZEICHEN+1
mov al,20h
FILL_LOOP2:
dec ecx
mov BYTE PTR[edi+ecx],al

jnz FILL_LOOP2
add edi,LEER_ZEICHEN

.else
lea edi,englisch_buff
dec edi
.endif
xor ecx,ecx
mov ah,0Ah


KOPIERE_ENGLISCH_LOOP:
inc ecx
mov al, BYTE PTR[esi+ecx]
cmp ah,al
je WEITER2
mov BYTE PTR[edi+ecx],al
jmp KOPIERE_ENGLISCH_LOOP
jmp WEITER2





WEITER2:


dec ecx ;(davor ist meits ein 0dh)
mov BYTE PTR[edi+ecx],0

add ebx,ecx
.if ebx>zeilen_laenge
mov zeilen_laenge,ebx
.endif
lea edi, deutsch_buff
lea esi, englisch_buff
.if filter.english!=0
xchg edi,esi

.endif
invoke SendDlgM,ID_AUSGABE_LIST,LB_ADDSTRING,0,edi
invoke SendDlgM,ID_AUSGABE_LIST,LB_ADDSTRING,0,esi

inc ergebnisse

ret

Extr_und_add endp


SearchProc proc ;its a thread

mov vorherige_zeile,0
xor ebx,ebx
mov zeilen_laenge,0
SUCH_LOOP:
invoke BMBinSearch,ebx,pMemory,FileSize,addr ein_buffer,eingabe_laenge
;auszug vorbereiten(und auf g?ltigkeit checken!)
mov ebx,eax
cmp eax,-1
je EXIT

invoke Extr_und_add,pMemory,ebx
inc ebx

;invoke SendDlgM,hWin,ID_AUSGABE_LIST,LB_ADDSTRING,0,ebx
jmp SUCH_LOOP
EXIT:
mov search_flag,0

xor edx,edx
mov eax,zeilen_laenge
mov ebx,3
mul ebx
add eax,zeilen_laenge

invoke SendDlgM,ID_AUSGABE_LIST,LB_SETHORIZONTALEXTENT,eax,0

invoke SetIcon,search_flag

invoke wsprintf,addr erg_buffer,addr template_ergebnisse,ergebnisse
invoke SendDlgM,ID_ERGEBNISSE,WM_SETTEXT,0,addr erg_buffer

invoke ExitThread,0
invoke CloseHandle,hThread

ret

SearchProc endp




PS: It does not leake now (with this code)
Posted on 2003-01-16 14:58:10 by CDW
CDW,

your memory leak does not seem to stem from the use of local or global variables. Instead, it seems to stem from the way you terminate your thread:


invoke ExitThread,0
invoke CloseHandle,hThread

ret

SearchProc endp

Apparently you try to close the thread handle from within the thread, after you have already exited the thread, which is of course impossible. So the handle never gets closed. See the Win32 API help, section "ExitThread", for the consequences of not closing that handle:
Terminating a thread does not necessarily remove the thread object from the operating system. A thread object is deleted when the last handle to the thread is closed.

Reversing the order of the calls to ExitThread and CloseHandle should help.

Regards, Frank
Posted on 2003-01-16 15:28:50 by Frank
if you exit your thread at the end of the threadproc, just "ret" instead of calling exitthread. also, let the spawning thread do the closehandle.
Posted on 2003-01-16 15:34:46 by f0dder
@fl0dder: you say,i don't need to call "ExitThread", i should use "ret" ?
Frank: it sounds logical - if i don't exit my Thread in a right way, my stack cause this mem leack
thx @all...
Posted on 2003-01-17 09:51:52 by CDW
ok, i fixed it - it was not the Thread (a very small leak because of "ExitThread" and then "CloseHandle"). It was the listbox - i take it out and the runsize is only 5600 KB now (its ok,because i map a 4,76 MB file). thx a lot @all (hm,but what should i use instead of listbox)
Posted on 2003-01-18 12:31:28 by CDW