mem leak blues
BlitzMax Forums/BlitzMax Programming/mem leak blues
| ||
I have an array of types which has a type in one of its fields when I delete an array item i'm doing this maxob:-1 For Local i:Int=c_ob To maxob obs[i]=obs[i+1] Next obs[maxob+1].msm=Null obs[maxob+1]=Null obs=obs[..maxob+1] any ideas where I might be going wrong? |
| ||
With the way the garbage collector works you should be able to delete the instance by simply doing obs = obs[..maxob + 1] . In fact you can do everything that whole piece of code does like this. maxob:-1 obs = obs[1.. ] |
| ||
ignore the for loop that was so I could remove somthing mid array you'd think you'd be right, but it's leaking like a sieve! |
| ||
try this Chris CPrint GCMemAlloced() Local maxob% = 10 Local obs[] = New Int[maxob] Print GCMemAlloced() maxob:-1 obs = obs[1.. ] GCCollect() Print GCMemAlloced() EDIT: heres the results I get: 13664 13750 13170 <-- Crazzy! EDIT 2: Better example :P Print "Mem = " + GCMemAlloced() Local maxob% = 10 Local obs[] = New Int[maxob] For i = 0 To maxob - 1 obs[i] = i Next Print "Mem = " + GCMemAlloced() Print "Last object value = " + obs[maxob - 1] Print "First object value = " + obs[0] maxob:-1 obs = obs[1..] Print "Last object value = " + obs[maxob - 1] Print "First object value = " + obs[0] GCCollect() Print "Mem = " + GCMemAlloced() |
| ||
doesnt make any difference if I [1..] or [..x+1] still leaking like crazy obs contains another type that holds a milkshape model type that has a texture and bunch of vert's I even tried assigning all its arrays as =null but its still leaking and the memory in the task manager *never* goes down... Print "Mem = " + GCMemAlloced() Local maxob% = 1000 Local obs[] = New Int[maxob] For i = 0 To maxob - 1 obs[i] = i Next Print "Mem = " + GCMemAlloced() Input$ For x=0 To 999 maxob:-1 obs = obs[1..] Next GCCollect() Print "Mem = " + GCMemAlloced() Input$ although gcmemalloced goes down in taskmanager the memory used doesnt go down |
| ||
Because BlitzMAX uses memorypools to manage memory. Allocating and deallocating memory is an expensive operation, reusing it is not. You cannot prove a memory leak in 7 lines of staic code (unless you're doing your own memory management). You have to have real code running for several hours, and notice a significant change in memory footprint. If you have a real memoryleak, the OS will start swapping memory around like crazy. |
| ||
found it there where int used instead of tbank for 2 createbanks... gcalloced goes back down to the same value when items are deleted, but mem used in the task manager only ever goes up (Every time I create an object) it sometimes goes down but seems to be behaving okay as if i create 100 objects then delete them then create 10 more it doesnt go any higher... So I guess max is keeping hold of allocated memory in case it needs it for somthing else? |