PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

More on "Memory Leaks"

Kornalius,

A "new" one ... there getting a little more subtle each time.

Refer to these two "Test" procedures. You can paste them into my "Test Environment" code (overwriting the existing procs of the same name) that I used yesterday for demonstarting memory leaks.

Code:

proc DoTestProc1(hWnd$, Msg$, wParam$, lParam$)
local (lst$, aString$, bString$);

print("Test Proc #1 (aString$ = GetCSV()) started");
DebugCount$ = TickCount$;
aString$ = "arg1,arg2,arg3 arg4,arg5";

CheckMenu (showMenu$, 1601, true);
while (MenuChecked (showMenu$, 1601))
bString$ = GetCSv(aString$,1);

ProcessMessages;
end;

print("----------------------------------------");
end;


Code:

proc DoTestProc2(hWnd$, Msg$, wParam$, lParam$)
local (lst$, aString$, bString$);

print("Test Proc #2 (if GetCSV() ...) started");
DebugCount$ = TickCount$;
aString$ = "arg1,arg2,arg3 arg4,arg5";

CheckMenu (showMenu$, 1602, true);
while (MenuChecked (showMenu$, 1602))
if (GetCSv(aString$,1) == "TEST")
bString$ = "abcdef";
end;

ProcessMessages;
end;

print("----------------------------------------");
end;


The func that these routines call (GETCSV(aString$,index$)) is below (for completeness ... it is already in the "utils.ppl" file withing my "test environment"

Code:

func GetCSV(aString$,index$)
local(lst$);

List(lst$);
StrTolist(aString$,",",lst$);
index$--;
if ((index$ >= 0) & (index$ < count(lst$)))
goto (lst$,index$);
return (str(lst$));
else
return("");
end;
end;


Now if you run Proc#1 you will find it DOES NOT show any memory leaks. Its a tight loop calling GetCSV and assigning the result to a string.

If you run Proc#2 it DOES LEAK MEMORY. It is also a call to GetCSV, with the same parameters, but this time in the context of an if (GetCSv == ?) ... end; context.

Sorry to keep throwing them up, but everyone we solve will help make the final release more stable.
The reason you get this leak is because in the second loop you don't assign the returned value from GetCSV() to any variable. This value is then added to the garbage collection and only freed at the end of the program, therefore still there during the loop.

I will try to find a way to tighten the garbage collector in cases like that.
Ok, the garbage collector is way more precise now. It doesn't wait for the end of the procedure or the end of the program to clean it's collection. Every internal command does it's garbage cleanup now. I get no memory leak anymore this way.

Thanks for taking the time to do these testings, it helps me a whole lot. I have some much to do for PPL.
Kornalius,

Success!

Not only does that "test" program now show no memory leaks, but running my "gpstrak" program for 5 minutes shows no memory leaks - prior to this last set of changes it was leaking about 16Kb / minute.

Thanks
Super. I spent an terrible amount of time on this, delaying the other stuff on my list and possibly the release date. But... It was worth it big time. I am glad you kinda pushed me to fix this it. I wanted to get to it someday. I still have a few things to finish up tomorrow on this issue. Then I guess next week I can finish up the remaining stuff (visual form builder for the ppc is a huge amount of work).

Again thanks a million for your time.
Today, I have simplified the internal structure of the garbage collection system. It is a bit faster and is more stable than previous versions.