can you create memory leaks without using lists?

BlitzMax Forums/BlitzMax Programming/can you create memory leaks without using lists?

Najdorf(Posted 2005) [#1]
I was wondering...


N(Posted 2005) [#2]
If you want a memory leak, try this...

While True
   MemAlloc( 2 )
Wend



Najdorf(Posted 2005) [#3]
I dont even know what that does


Amon_old(Posted 2005) [#4]
lol


Perturbatio(Posted 2005) [#5]
I dont even know what that does

it continuously allocates 2 bytes of memory each loop cycle until you cancel the program, but since the memory is not being freed (nor assigned to anything) it is in essence a memory leak.


Najdorf(Posted 2005) [#6]
Ok, but I dont know how to use it anyway.

The question is more "if I dont use lists (arrays instead) and dont use "alloc", do I possibly risk memory leaks or I'm completely safe?"


N(Posted 2005) [#7]
You're fine if the data is referenced 'normally'. I'd guess that means not by a pointer (other than Object).


Koriolis(Posted 2005) [#8]
IMHO opinion the most insidious source of memory leaks in BlitzMax is when you happen to create circular references. The simplest example of it being:
Type SomeType
    Field bla:SomeType
End Type
Repeat
    t:SomeType = New SomeType
    t.bla = t
    FlushMem
Forever
Here you get a memory leak because none of the created objects will ever be released, even though you call FlushMem continously and the objects are not referenced anymore.
At least, this is documented.