SRL Archive - Senior News and General

Memory


Smartzkid

2010-01-30 01:37:54

The following thread got me thinking - how many people really know/care about proper memory management? Maybe the DIM errors that have been going around are more the fault of the scripters than they are of SCAR?

http://www.villavu.com/forum/showthread.php?p=680242 (i lolled)

Granted, I rarely read through scripts anymore, but if many people make these mistakes, perhaps it would be worth the time spent to write a tutorial on the details of memory management? I am no expert when it comes to tutorial writing, but if anyone would like to put the words down, I would be very willing to help with examples and other solutions!

Nava2

2010-01-30 03:54:59

I agree, I commonly see people making the error of reloading dtms when freeing. As well, freeing too soon or not at all.

Good catch!

YoHoJo

2010-01-30 04:00:28

I agree memory management is very important. But besides DTMs/Bitmaps are there any other little things people do inefficiently that could use less memory?

Nava2

2010-01-30 04:01:56

Forms?

YoHoJo

2010-01-30 04:03:54

From: Nava2
Forms?


Who uses those anymore!? :p

Wizzup?

2010-01-30 06:35:40

From: Smartzkid
The following thread got me thinking - how many people really know/care about proper memory management? Maybe the DIM errors that have been going around are more the fault of the scripters than they are of SCAR?

http://www.villavu.com/forum/showthread.php?p=680242 (i lolled)

Granted, I rarely read through scripts anymore, but if many people make these mistakes, perhaps it would be worth the time spent to write a tutorial on the details of memory management? I am no expert when it comes to tutorial writing, but if anyone would like to put the words down, I would be very willing to help with examples and other solutions!


If SCAR does proper memory management, it will warn the scripts if they try to free and invalid object, rather than free it even if it does not exist and then crash.

marpis

2010-01-30 06:58:49

Question:


function LoadDTM: Integer;
begin
result := DTMFromString('akjdakjdakjda');
end;

procedure DoTehSex;
begin
if FindDTM(LoadDTM, X, Y, MMX1, MMY1, MMX2, MMY2) then // Here the DTM is loaded...
writeLn('Hasselhoff');
// ...but what happens to it now?
end;

Wizzup?

2010-01-30 07:08:57

From: marpis
Question:


function LoadDTM: Integer;
begin
result := DTMFromString('akjdakjdakjda');
end;

procedure DoTehSex;
begin
if FindDTM(LoadDTM, X, Y, MMX1, MMY1, MMX2, MMY2) then // Here the DTM is loaded...
writeLn('Hasselhoff');
// ...but what happens to it now?
end;


The reference to the DTM is lost, and it will not be freed.
Look for a memory management tutorial made by pups. It's gotta be in here somewhere. :)

mixster

2010-01-30 10:20:03

I some what brought it up a while ago with my own form of memory management

See here

As long as all calls went through the wrapper functions, it would keep track of everything and show which ones weren't freed, a useful descriptor of where they were etc and as I said, could be branched to DTM's.

The main problem is it seems most people don't see memory leaks as a problem. As far as they are concerned, if it does what is needed, then it doesn't matter. Bad programming practices are all too common when you don't have a forum of programmers :)

Edit: Upon reading through, I see you were there :O

Wanted

2010-01-30 11:24:04

My DTMs and bmps are always freed and loaded locally… mainly because they are only used in that function/procedure I use them in.

Forms are global, but they are always freed…

  try
SafeInitForm;
SafeShowFormModal;
except
WriteLn('Error in form!');
finally
FreeForm(Form);
FreeBitMap(BackgroundPicture);
end;

mixster

2010-01-30 15:01:58

Forms aren't an issue at all really - they're only a small amount of one use memory. Failure to allocate DIB handles during runtime is what comes up a lot and is normally because they've forgotten to free a bitmap and it's repeatedly created.

Also, global bmp's and dtm's are a better idea than local only ones when it comes to the general masses since you only need to load them once and so it would only be a small bit of unfreed memory (that Scar would handle when the script terminated anyway).

As a bit of further justification, (all based on my experiences) normally if global var's are involved in memory leaks, then it's because they slipped the load procedure into a repeating loop rather than just the setup. However, when local ones are concerned they may be not freed in every procedure that uses them and sometimes they are conditionally freed (since quite a few like to use exit and usually have the free'ing at the end) and the like so it all becomes a lot more complex to debug.

Bebe

2010-01-30 15:06:11

From: Wizzup?
The reference to the DTM is lost, and it will not be freed.
Look for a memory management tutorial made by pups. It's gotta be in here somewhere. :)

Isn't it stickied in dev section?

Wizzup?

2010-01-30 15:10:36

From: Bebe
Isn't it stickied in dev section?


Possibly, I don't know.

Markus

2010-01-30 17:03:26

http://www.villavu.com/forum/showthread.php?t=1359

Smartzkid

2010-01-31 02:14:07

Why does FreeDTM not accept DTM indices as variables so it can set them to -1? This would allow us to implement some of the more complicated memory management systems with a bit less overhead.

Worth requesting from Freddy?

mixster

2010-01-31 05:28:48

No one knows, but I don't think it is worth requesting - in the end it should be up to the scripters to handle it and it's a great way to subtly tell a scripters skills. If you are desperate, you can always just make a wrapper function that does that fine

Even my method I only produced as an easy way to debug bitmap based memory leaks in one of my large Scar games using forms where I was using ~5 global bitmaps and using between 5 and 10 bitmaps in several procedures - I would think most people wouldn't have this many to keep track of and so any advanced form of memory management would be quite wasted effort.