Test files invoke undefined behavior and memory leaks.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Test files invoke undefined behavior and memory leaks.

WBahn
Administrator
The MemoryTest program dinks around at specific memory locations in the heap space in the vicinity of address 8000. But these locations are fair game to be allocated and corrupted by the metadata stored with the memory blocks. I realize that the locations are in the middle of the heap and thus, hopefully, well away from any blocks that get allocated regardless of which end allocations starts from.

This may well be a perfectly reasonable way to test the peek() and poke() functions, but I think the assumptions should be documented in the file so that students are not led down the path of thinking that this is good programming practice.
 
In several test files string constants are used as arguments to functions. But this results in a memory leak as there is no mechanism to dispose of these constants once the functions return.

My concern is that this sets a bad example for students, who are naturally going to look at supplied Jack files for hints on how to do things "correctly". I've had students that ran themselves out of heap space by printing the score in their game within a loop.

I think that either handling string constants correctly should be covered in the text or the grammar should be modified so as not to allow string constants to be used as arguments to functions. Admittedly, a casual glance on the grammar doesn't reveal a simple way to do either. If that's the case, then I would still argue that this memory leak should be explicitly discussed (it's good fodder for discussion, anyway) and the supplied code should not invoke it (at least not without having comments in the code expressly pointing out that this is being done as an expedient).