tweakmeup Posted December 2, 2012 Share Posted December 2, 2012 Everythings been working fine, then all of a sudden I get runtime errors for all my finddtmrotated functions. It says access violation at address 00e16xxxxxxxx. How do I fix this, cause its not letting my functions do their job! Quote Link to comment Share on other sites More sharing options...
LordJashin Posted December 2, 2012 Share Posted December 2, 2012 1. Post your code 2. Always first Try restarting SCAR... Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 2, 2012 Share Posted December 2, 2012 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 Quote Link to comment Share on other sites More sharing options...
Mysterio Posted December 3, 2012 Share Posted December 3, 2012 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? Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 3, 2012 Share Posted December 3, 2012 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 Quote Link to comment Share on other sites More sharing options...
Mysterio Posted December 3, 2012 Share Posted December 3, 2012 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! Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 3, 2012 Share Posted December 3, 2012 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 Quote Link to comment Share on other sites More sharing options...
Mysterio Posted December 3, 2012 Share Posted December 3, 2012 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? Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 3, 2012 Share Posted December 3, 2012 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 Quote Link to comment Share on other sites More sharing options...