Welcome Guest. Please Login or Register. Apr 1st, 2018, 03:33am
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. We apologize Conforums does not have any export functions to migrate data. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
Memory leak detection
« Thread started on: Jan 9th, 2015, 12:34pm »
It's not difficult to cause a memory leak in Liberty BASIC, typically this will happen if you jump out of a loop with GOTO rather than EXIT. This is an insidious fault, because your program may continue to run for minutes or hours or even longer, and then fail without warning when all the free memory is used up.
To help diagnose this problem I plan to enhance the LBB debugger so that it displays the current heap and stack usage. If either value increases inexorably as your program runs, it indicates a probable leak.
Can jumping out of an error handler with a goto rather than a resume cause a memory leak or another downside?
It's possible, but not very likely. If you use an ON ERROR GOTO in a subroutine, function or loop (FOR, WHILE, DO) it is automatically cancelled (and the memory it used freed) on exit.
So the only circumstance when a memory leak could result is if the ON ERROR GOTO is used in the 'lowest level' of your program, when you aren't in a function or loop. In that case you should explicitly cancel the error trapping using:
Code:
ON ERROR GOTO 0
Of course if jumping out of the error handler also means you have jumped out of a loop then certainly there will be a memory leak, but that's not directly related to the error trapping.
The current version of LBB (2.86) displays the heap and stack usage in the debugger, so if you are worried about the possibility of a memory leak from this cause in your own program(s) you can check it.