Re: Error while running VM code in VMEmulator

The snake game works fine. But if I let it run for sometime (for about a minute) it shows following error:
Program Halted: Heap Overflow.

Your game has a "memory leak". Snake.Advance() keeps doing

let prsntMove = Array.new(length);

but never calls

do prsntMove.dispose();

This means that every time Advance() is called, a new instance of prsntMove is allocated from the heap and that memory is gone forever. Eventually you run out of heap.

Note: although not needed in your current game, all classes that create objects in their constructors should have a destructor ("method dispose()" in Jack) that destroys those objects. Class Snake shoud get: