ccrma / chuck

ChucK Music Programming Language
http://chuck.stanford.edu/
GNU General Public License v2.0
803 stars 128 forks source link

Memory leak from Chuck_Objects returned from CPP functions (reference counting error?) #371

Closed AndrewAday closed 10 months ago

AndrewAday commented 11 months ago

example program that leaks (Chuck_object returned from CGL.nextFrame() is not freed)

while (true) { CGL.nextFrame() => now; }

+d of above program

[gameloop.ck]: while( true ) {
[gameloop.ck]: /** loop conditional **/ true;
[gameloop.ck]: [0] Chuck_Instr_Reg_Push_Imm( 1 )
[gameloop.ck]: [1] Chuck_Instr_Reg_Push_Imm( 0 )
[gameloop.ck]: [2] Chuck_Instr_Branch_Eq_int( 13 )
[gameloop.ck]: CGL.nextFrame() => now;
[gameloop.ck]: [3] Chuck_Instr_Reg_Push_Imm( -1748711280 )
[gameloop.ck]: [4] Chuck_Instr_Dot_Static_Func( func=0000013597D6A100 )
[gameloop.ck]: [5] Chuck_Instr_Func_To_Code(  )
[gameloop.ck]: [6] Chuck_Instr_Reg_Push_Imm( 0 )
[gameloop.ck]: [7] Chuck_Instr_Func_Call_Static( 1 )
[gameloop.ck]: [8] Chuck_Instr_Reg_Push_Now(  )
[gameloop.ck]: [9] Chuck_Instr_Reg_Pop_Word2(  )
[gameloop.ck]: [10] Chuck_Instr_Event_Wait(  )
[gameloop.ck]: [11] Chuck_Instr_Reg_Pop_Word2(  )
[gameloop.ck]: [12] Chuck_Instr_Goto( 0 )
[gameloop.ck]: } /** while( true ) **/
[gameloop.ck]: [13] Chuck_Instr_EOC(  )
[gameloop.ck]: -------

Example of code that DOES free memory correctly:

fun Object get()
{
    return new Object;
}

get() @=> Object obj;
get();
gewang commented 10 months ago

issue addressed as of 1.5.1.7

[gameloop.ck]: -------
[gameloop.ck]: while( true ) {
[gameloop.ck]: /** loop conditional **/ true;
[gameloop.ck]: [0] Chuck_Instr_Reg_Push_Imm( 1 )
[gameloop.ck]: [1] Chuck_Instr_Reg_Push_Imm( 0 )
[gameloop.ck]: [2] Chuck_Instr_Branch_Eq_int( 16 )
[gameloop.ck]: GG.nextFrame() => now;
[gameloop.ck]: [3] Chuck_Instr_Stmt_Start( numObjReleases=1 this=0x60000298f390 )
[gameloop.ck]: [4] Chuck_Instr_Reg_Push_Imm( 4955765920 )
[gameloop.ck]: [5] Chuck_Instr_Dot_Static_Func( func=0x600003609c00 )
[gameloop.ck]: [6] Chuck_Instr_Func_To_Code(  )
[gameloop.ck]: [7] Chuck_Instr_Reg_Push_Imm( 0 )
[gameloop.ck]: [8] Chuck_Instr_Func_Call_Static( 1 )
[gameloop.ck]: [9] Chuck_Instr_Stmt_Remember_Object( offset=0 start=0x60000298f390 )
[gameloop.ck]: [10] Chuck_Instr_Reg_Push_Now(  )
[gameloop.ck]: [11] Chuck_Instr_Reg_Pop_Float(  )
[gameloop.ck]: [12] Chuck_Instr_Event_Wait(  )
[gameloop.ck]: [13] Chuck_Instr_Stmt_Cleanup( numObjRelease=1 start=0x60000298f390 )
[gameloop.ck]: [14] Chuck_Instr_Reg_Pop_Float(  )
[gameloop.ck]: [15] Chuck_Instr_Goto( 0 )
[gameloop.ck]: } /** while( true ) **/
[gameloop.ck]: [16] Chuck_Instr_EOC(  )
[gameloop.ck]: -------