Jump to content
tweakmeup

runtime error??

Recommended Posts

This could be because of memory leak. Maybe you have a loop in your code that keeps loading data to memory, but you ain't freeing it. So eventually you run out of memory and errors like this start popping up like crazy!

 

Like LJ said already, post your code, because there's very little we can do about it without seeing what you have wrote. :\

 

-Jani

Link to comment
Share on other sites

This could be because of memory leak. Maybe you have a loop in your code that keeps loading data to memory, but you ain't freeing it. So eventually you run out of memory and errors like this start popping up like crazy!

 

Like LJ said already, post your code, because there's very little we can do about it without seeing what you have wrote. :\

 

-Jani

 

I think I have the same problem too with my log out script (and it's loops) I needed help with a little while back; how would I go about freeing the memory?

Link to comment
Share on other sites

I think I have the same problem too with my log out script (and it's loops) I needed help with a little while back; how would I go about freeing the memory?
Hey Mysterio,

Fonts: FreeChars2(i: Integer); [i = fontset ID]

DTMs: FreeDTM(DTM: Integer);

Bitmaps: Bmp.Free; [bmp = TSCARBitmap]

Arrays: Set(Array)Length(arr, 0); [arr = your array]

 

Reason to tweakmeup's problems wasn't the need for freeing data though.. It was the fact that tweak tried to use DTMs before they were even loaded for SCAR to use.

 

Mysterio, you can always PM me your script and I can check it out whats wrong with it. :)

 

-Jani

Link to comment
Share on other sites

Bitmaps: Bmp.Free; [bmp = TSCARBitmap]

 

I think that's it there. I have my procedures running on a loop, and 5 out of 6 of them are checking for bitmaps. So I'm going to take a stab right now and add in a procedure to free the bitmaps.

 

If I still get the runtime error, I'll PM the script to you - I appreciate that, thanks mate!

Link to comment
Share on other sites

Mysterio, remember that you don't have to keep freeing em, if you keep using them all the time. Just free them in the end of the script (at mainloop OR with ScriptTerminate).

 

But if you are using something that you only need temporarily, then its good to free them.

 

Always remember this "thumb-rule": Free any and every object before you [re]load (new) data to em.

 

Examples:

 

Do NOT do this mistake (not so bad without loop, but inside a loop you will run out of memory pretty quickly):

begin
 yourDTM := DTMFromString('78DA63F...');
 yourDTM := DTMFromString('65FA47B...'); // <== Will add MEMORY LEAK! Because you haven't free'd the already data before loading new data. 
 FreeDTM(yourDTM); // This frees only the last loaded data, the first loaded data will still remain loaded to memory.
end.

 

Do this:

begin
 yourDTM := DTMFromString('78DA63F...');
 FreeDTM(yourDTM);
 yourDTM := DTMFromString('65FA47B...');
 FreeDTM(yourDTM);
end.

 

-Jani

Link to comment
Share on other sites

Ok well this is what I tested:

 

procedure freethebmps;
 begin
 Ab.free;
 ac.free; 
 te.free;
 dom.free; 
 ski.free;
 outt.free;
 WriteLn('Bmps set free');
 end;

 

The script has been flawless ever since.

 

I just call the procedure at the end of my procedure list loop. Is that a decent way or am I still unnecessarily using system resources?

Link to comment
Share on other sites

Well, there's 2 kind of objects you could use. Local and Global:

 

var
 global: TSCARBitmap;

procedure ExampleB;
var 
 local: TSCARBitmap;
begin
 local := TSCARBitmap.Create('');
 local.Free;
end;

begin
 global := TSCARBitmap.Create(''); // You can use this in ExampleB procedure aswell, because this is a global bitmap.
 ExampleB;
 global.Free;
end.

 

I'd say, any bitmaps that you use really often (all the time) in your script, make them global.

Those that you use rarely, make them local.

 

I would say, with global bitmaps don't do this:

 

begin
 repeat
   LoadBitmaps;
   yourProcedureA;
   yourFunctionA;
   yourProcedureB;
   FreeBitmaps;
 until False;
end.

 

Do this instead:

 

begin
 LoadBitmaps;
 repeat
   yourProcedureA;
   yourFunctionA;
   yourProcedureB;
   FreeBitmaps;
 until False;
 FreeBitmaps;
end.

 

OR this (I use this method aswell):

 

procedure FreeBitmaps;
begin
 yourBitmapA.Free;
 yourBitmapB.Free;
end;

procedure ScriptTerminate;
begin
 FreeBitmaps;
end;

begin
 LoadBitmaps;
 repeat
   yourProcedureA;
   yourFunctionA;
   yourProcedureB;
 until False;
end.

 

That way it wont keep loading/freeing all the time, when its really not needed at all. :)

 

-Jani

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...