Log in

View Full Version : Guidelines for preventing memory leak?



Main
06-21-2012, 10:44 PM
Is there any guideline on what causes memory leak or even increase in memory usage?


I am working on a project atm, and it doesn't have SPS,Bitmap,DTM,OBDTM..etc and I'd just like to make sure my script wont build up excess ram usage.


For example, does local var gets cleared when not using the function?

Does two different local var has same name some how share their memory address? (I think its unlikely).

If a array/tpa only has 10 slots used, would initially:

SetLength( ATPA, 99);
or
SetLength( ATPA, 10);
takes up different ram?


Any help or info about ways to reduce memory usage would be greatly appreciated, by myself and many others who want to write a efficient script :)

putonajonny
06-21-2012, 11:00 PM
Open TaskManager Processes tab, find simba then run this... you'll have an answer to one of your questions
program new;
Function DoStuff : Boolean;
Var
A : array [0..2000000] of TPoint;
begin

WriteLn('Function Started');
Wait(5000);
WriteLn('Function Ended');


end;
begin

Repeat
DoStuff;
Wait(5000);
Until(false);

end.
About 10mb of memory for that array created and destroyed on each run of the function

Change that number to 20000000 and you'll get your answer to a different question

Also, some TPointArray functions have memory leaks so use wrappers, I don't know much about this stuff (I'm only learning)

Edit:
If you change that number to 200000000 then 1.5gb of memory is created and destroyed in 5 seconds... wow