Memory Leak (Program Bug and Problems)

by Andrew360 @, Wednesday, July 24, 2013, 15:22 (1520 days ago)
edited by Andrew360, Wednesday, July 24, 2013, 15:36

After running this program for about 10 minutes in version 0.9.9.49 (even stopping, editing, and running again), it would suddenly stop and then crash. I reopened it, ran it, and watched the task manager the [Memory (Private working set)] tab showed Basic's memory continually rising about 3,000 K every second until it reached around 550,000 K and crashed. I updated to version 0.9.9.58 and the same thing happened, except that it did not crash and continued rising past 600,000.

I have noticed the same thing happening in other programs with 2-dimensional arrays.

Here is the program. It is somewhat similar to the Game of Life but with very different rules determined by the md5 hash of code$, for a reproducible random.


code$="anything"
colorful=true

#anything Pascal's triangle

#123 Pascal's triangle (2)

#351 Moving stuff

#100 Checkers


a$=left(md5(code$),9)

#a$="000000000"

r$=""
for i=1 to 9
r$=r$+right("0000"+string(tobinary(fromhex(mid(a$,i,1)))),4)
print i-1+" "+right("0000"+string(tobinary(fromhex(mid(a$,i,1)))),4)
next i

graphsize 400,400
graphvisible 1
global grid
fastgraphics

dim grid(100,100)
dim newgrid(100,100)
colors={darkgrey,black,blue,darkblue,green,darkgreen,cyan, darkcyan,red,darkred,purple,darkpurple,yellow,darkyellow,white,grey}

do

#draw

if not(colorful) then

color black
rect 0,0,400,400
color white
for x=0 to 99
for y=0 to 99
if grid[x,y]=1 then rect x*4,y*4,4,4
next y
next x

else

for x=0 to 99 step 2
for y=0 to 99 step 2
color colors[1-grid[x,y]+grid[x+1,y]*2+grid[x,y+1]*4+grid[x+1,y+1]*8]
rect x*4,y*4,8,8
next y
next x

endif
refresh

#simulate
for x=0 to 99 step 2
for y=0 to 99 step 2
a=g(x-1,y)+g(x,y-1)+g(x+1,y-1)+g(x-1,y+1)+g(x+2,y+1)+g(x+1,y+2)+g(x+2,y)+g(x,y+2)
a$=mid(r$,a*4+1,4)
newgrid[x,y]=int(mid(a$,1,1))
newgrid[x+1,y]=int(mid(a$,2,1))
newgrid[x,y+1]=int(mid(a$,3,1))
newgrid[x+1,y+1]=int(mid(a$,4,1))
next y
next x

#update
for x=0 to 99
for y=0 to 99
grid[x,y]=newgrid[x,y]
next y
next x

until 0

function g(x,y)
g=0
if x>-1 and y>-1 and x<100 and y<100 then g=grid[x,y]
endfunction

Memory Leak

by Jim ⌂ @, Russell, KY, Thursday, August 01, 2013, 20:14 (1512 days ago) @ Andrew360

Andrew,

That was a tough one. I was not releasing a variable object when the variable was loosing scope in a function return. I believe that the new release 0.0.0.64, that I just pushed out to Sourceforge, should fix your issue.

Give it a whirl and let me know.

Jim

RSS Feed of thread
powered by my little forum