SRL Archive - Help and Support

Memory in my script


Le Jingle

2012-08-27 14:58:09

First: Sorry for making so many threads in this help section :s [However, I truly value them enough to make them! 0:-) ]

Detail: I've written a fletching script for use at soul wars, and my memory builds ~10mb/hr on the Simba.exe process.. Afaik, I'm doing everything I should in the script to free memory, and I'm wondering if it's me missing something, or is pascalscript faulting somewhere, or is it something I'm completely missing all together?


program SW_maple_long_u;
{$DEFINE SMART}
{$i srl/srl.simba}

// Thanks to the SRL community; At least half of what I learned resides from SRL members!

const
tofletch = 200000;

var
dtm, Loads, banked, preformed, overall, fletched: integer;

procedure declareplayers; // Add players to be ran here... 1 player per 6hrs
begin // so add your player here 4 times for 24hrs runtime.
HowManyPlayers:= 3;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer:= 0;
with Players[0] do
begin
Name := '';
Pass := '';
Active := True;
WorldInfo := [True, 2];
end;
with Players[1] do
begin
Name := '';
Pass := '';
Active := True;
WorldInfo := [True, 2];
end;
with Players[2] do
begin
Name := '';
Pass := '';
Active := True;
WorldInfo := [True, 2];
end;
end;


procedure SetDTMs_; // load maple log dtm
begin
dtm := DTMFromString('mVAEAAHicE2BgYMhmZGCIBeIiIC6BsqOAOB6IU4A4B4gzgDgfKl8O' +
'xBVQXArEP4FmfAbiL0D8AYr/AvF/IGZihNAMQPofVPwPA0TPV6i+M' +
'AsekEqyMT+QpAQzUojRAQAJ3BYr');
end;


procedure LeFreeDTM; // free maple log dtm
begin
freedtm(dtm);
end;


procedure Setup; // Basic script setup, small account for lag too.
begin
ClearDebug;
ActivateClient;
DeclarePlayers;
LogInPlayer;
Wait(RandomRange(200, 6000));
CompassMovement(30, 150, false);
Wait(RandomRange(100, 1500));
MakeCompass('W');
Findnormalrandoms;
SetAngle(SRL_ANGLE_HIGH);
Wait(RandomRange(400, 600));
Wait(RandomRange(100, 3000));
ChatsOff;
ExitSquealOfFortune();
end;


procedure Login_help;
var
t: integer;
begin
MarkTime(t);
while (not LoggedIn) do
begin
wait(500+Random(500));
if LoginPlayer then
begin
Wait(RandomRange(200, 6000));
CompassMovement(30, 150, false);
Wait(RandomRange(100, 1500));
MakeCompass('W');
Findnormalrandoms;
SetAngle(SRL_ANGLE_HIGH);
Wait(RandomRange(400, 600));
Wait(RandomRange(100, 3000));
ChatsOff;
ExitSquealOfFortune();
break;
end;
wait(1000+random(500));
if (TimeFromMark(t) > 360000) then
begin
writeln('did not login after 6 minutes.. attempting next player');
NextPlayer(True);
end;
end;
end;


procedure Cancel_script(s: string; LeLogout, LeTerminate: Boolean);
begin // Leaves a message, optional logout, optional terminate script
WriteLn(s);
if LeLogout then
LogOut;
if LeTerminate then
TerminateScript;
end;


procedure Banking_main;
var
t, w: Integer;
begin
if not LoggedIn then
Exit;
w := 0;
MarkTime(t);
if OpenBankChest(SRL_BANK_SW) then
writeln('')
else
Cancel_script('removed, shutting off ~ ciao', true, true);
if WaitFunc(@BankScreen, 250, 15000) then
begin
DepositAll;
IncEx(Loads, 1);
Wait(RandomRange(100, 115));
Withdraw(9, 0, 100);
CloseBank;
Wait(240+Random(45));
Exit;
end else
if not (BankScreen) then
begin
FindNormalRandoms;
repeat
if (timefrommark(t)>=30000) Then
exit;
if (w = 5) then
exit;
OpenBankChest(SRL_BANK_SW);
Wait(2500+Random(1000));
IncEx(w, 1);
until(BankScreen);
end;
end;


procedure Antiban_optional; // small antiban, counts preformed & skipped occurences
begin // lowering randomness will just affect efficiency,
case Random(1500) of // reaching tens on mills of xp with just this antiban.. [personally]
0..1: begin incex(preformed, 1); PickupMouse; end;
2: begin incex(preformed, 1); IdleTime(500, 500, 5); end;
3: begin incex(preformed, 1); SleepAndMoveMouse(1500); end;
4..1500: begin incex(overall, 1); wait(randomrange(50, 100)); end;
end;
wait(20+random(10));
end;


function WhiteTxtChatWrap: boolean; // finds the white text color in the chat screen
var
x, y: integer;
begin
result := FindColorSpiralTolerance(x, y, 16777215, MCX1, MCY1, MCX2, MCY2, 5);
end;


function LocateUnstrungWrap: boolean; //finds inv slot of unstrung maple longbow color
begin
result := CountItems('color', 6711926, [25, 10]) > 1;
end;


function ClickThruChat: boolean; // Clicks through chat screen interface(s)
var
t: integer;
begin
result := false;
if not LoggedIn then
Exit;
marktime(t);
repeat
if WhiteTxtChatWrap then
Mouse(MCCX+2, MCCY+21, 25, 25, mouse_left);
wait(1750+random(750));
until(timefrommark(t)>10000) or (LocateUnstrungWrap);
if LocateUnstrungWrap then
result := true
else
exit;
end;


function Fletch_Logs: boolean;
var
x, y, t: Integer;
fast_slots: TIntegerArray;
begin
result := false;
if not LoggedIn then
Exit;
fast_slots := [1, 5, 9, 13];
//WaitFindDTMEx(DTM: integer; var x, y: integer; xs, ys, xe, ye, WaitPerLoop, MaxTime: integer): boolean;
if WaitfindDTMEx(dtm, x, y, MIX1, MIY1, MIX2, MIY2, 100, 5000) then
// if finddtm(dtm, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
//mouse(x, y, 7, 7, mouse_left);
mouseitem(fast_slots[random(4)], mouse_left);
WaitFunc(@ClickThruChat, 250, 12500);
marktime(t);
repeat
if not LoggedIn then
break;
Antiban_optional;
wait(randomrange(500,1000));
until(timefrommark(t)>=53000) or (not(finddtm(dtm, x, y, MIX1, MIY1, MIX2, MIY2)));
incex(fletched, 28);
incex(banked, 1);
end;
result := true;
end;


function return_value(number_done: integer): longint;
var
i, r: integer;
begin
for i := 0 to number_done do
begin
if (random(3)=0) then
r := 59
else
r := 58;
result := r + result;
end;
end;


procedure Do_Report;
var
xp_temp, CutPerHR, XP_PerHR: int64;
begin
xp_temp := return_value(fletched);
XP_PerHR := round((xp_temp * 3600)/(gettimerunning/1000));
CutPerHR := round((fletched * 3600)/(gettimerunning/1000));
cleardebug;
writeln('[*].Time Running: '+MsToTime(integer(gettimerunning),time_formal)+'');
writeln('[*].Ttl Feltch Exp: '+tostr(xp_temp)+' (xp/hr: '+tostr(XP_PerHR)+')');
writeln('[*].Ttl Logs Cut: '+tostr(fletched)+' (cut/hr: '+tostr(CutPerHR)+')');
writeln('[*].Antiban`s: '+tostr(preformed)+'/'+tostr(overall)+'');
end;


procedure random_failsafe; // if we somehow leave soulwars, this will nuke the script given
begin // a random event is encountered [small failsafe]
srl_Warn('uhhh', 'Random detected; ciao!', warn_AllVersions);
Cancel_script('random detected; ciao!', true, true);
end;


function Check4YellowTxt:boolean; // Searches the mainscreen for yellow, game-update text
var
x, y: integer; // should work if we turn off all our chats
begin
Wait(20+random(10));
result := findcolor(x, y, 65535, MSX1, MSY1, MSX2, MSY2);
end;


procedure main_loop; // main loop, encases pretty much everything
var // here to help player surpass 6 hour runtimes
t, Random6hr: integer;
begin
WriteLn('Starting the main loop');
MarkTime(t);
Random6hr := RandomRange(21600000, 22500000); // (6hr, 6hr 15mins)
repeat

if not LoggedIn then
Login_help;

if Check4YellowTxt then
terminatescript;

if (TimeFromMark(t)>=Random6hr) then
exit;

Banking_main;
Fletch_Logs;
Wait(20+random(10));
Do_Report;

until(not loggedin) or (fletched = tofletch);
end;


begin // Main part of the script..
SRL_SixHourFix := True;
Smart_FixSpeed := True;
setupsrl;
SetDTMs_;
SRL_Procs[SRL_OnFindRandom] := @random_failsafe;
AddOnTerminate('LeFreeDTM');
Setup;

repeat

main_loop;

if not loggedin then
LoginPlayer;

until(fletched = tofletch) or (not loggedin);

writeln('everything complete? ciao');
terminatescript;
end.

Only 322 lines, any help would be appreciated.
*The script runs fine, but revisions are also appreciated. :)

Kasi

2012-08-27 15:20:25

hmm, your script seems perfectly fine, is there any point at where the memory spikes? 10mb is quite alot. are you sure its 10mb? i had this error a while ago, but it was to do with TPA's you dont have any TPA's..

Home

2012-08-27 15:22:20

I didn't see anything that would add more memory expect RS Itself, How much is your Memory usage after couple hours?

~Home

Le Jingle

2012-08-27 15:29:11

Well it rises every 6-10 minutes (in small spikes?) by about 1-1.5 mb. I'm testing it again for reading the ram every hour.

Script started at 41mb, it's 1hr 5mins running, currently 50.5mb ram usage.

Pretty sure it'll continue to rise like this, but I can edit in more accurate results to this post too as the hours pass by.

Should I try re-creating this script in lape and test to see if the memory still grows?

Thanks for the replies too!

Edit: 2nd hour = 60,604 kb ram, yet another personal verify of about +10mb ram/hr
(will keep editing in hourly usage if necessary)

Kasi

2012-08-27 15:36:24

From: Le Jingle
Well it rises every 6-10 minutes (in small spikes?) by about 1-1.5 mb. I'm testing it again for reading the ram every hour.

Script started at 41mb, it's 1hr 5mins running, currently 50.5mb ram usage.

Pretty sure it'll continue to rise like this, but I can edit in more accurate results to this post too as the hours pass by.

Should I try re-creating this script in lape and test to see if the memory still grows?

Thanks for the replies too!


yer just check the memory everytime you declare a variable etc.

Sin

2012-08-27 16:42:01

I had this problem too, I found that calling a DTM then freeing it RIGHT AFTER you use it will most likely fix it.

litoris

2012-08-28 04:32:49

Loops eventually build up memory, 1-1.5 MB every 10 minutes is regular I'd say.

masterBB

2012-08-28 07:01:08

Hmmm. Strange. Usually memory leak are easy for me to spot. Maybe a small leak in srl?

Le Jingle

2012-08-29 01:48:14

Indeed interesting, I found (currently on 1 machine, testing on another now) that NOT utilizing S.M.A.R.T. in the same Simba script (use of cross-hair drag -> RS Client), leaves the RAM use at a stable level (approx. the same RAM use throughout the entirety of 6 hours run time).


Ex.

1st machine [Simba.exe] steadied @ 53mb RAM consistently, w/o S.M.A.R.T.

2nd machine [Simba.exe] steadies currently @ 40mb RAM consistently, w/o S.M.A.R.T.
^ grew to 67mb after 2.5 hours; yet upon hitting stop/terminating the script, it reduced to 53mb.


Thus leading me to believe that S.M.A.R.T. might be the culprit (in some fashion)?

Also, person note: Reason behind posting this = discover what I'm doing that creates iffy memory usage. So, #disclaimer at my accusation towards S.M.A.R.T. - p.s. I still LOVE S.M.A.R.T.! :)

Kasi

2012-08-29 02:31:54

Smart is written in java, even if it might have a leak the gc would clear that up

P1ng

2012-08-29 02:56:09

SMART and Simba are now kept in two separate processes, this was as of 7.2/8.0 IIRC