|
2001-01-18
| ||
| 17:11 | • Closed ticket [229181ffff]: Compiler Leaks Memory plus 7 other changes artifact: a2aa4ed798 user: dkf | |
|
2001-01-17
| ||
| 22:18 | • New ticket [229181ffff]. artifact: 97e739b577 user: nobody | |
Compiler Leaks Memory
Closed / Invalid229181ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2001-01-17 22:18:11
Running and embedded interpreter from C++. The following code leaks memory.
...
while(1){
char* theScript = GetScript();
returnLength = NPstrlen( theScript );
theObj = Tcl_NewUnicodeObj(theScript, returnLength );
Tcl_EvalObjEx(theInterp, theObj , TCL_EVAL_DIRECT );
}
However, once you switch to pre-compiling the scripts into bytecode objects and using them, the leak disappears. Seems that the compile stage is not 100%.
dkfplain2001-01-18 17:11:31
The code, as written, is failing to call Tcl_IncrRefCount prior to calling Tcl_EvalObjEx amd Tcl_DecrRefCount afterwards. Add these calls and everything will be hunky-dory (assuming the string returned by GetScript() is cleaned up right too, of course.)
while(1){
char* theScript = GetScript();
returnLength = NPstrlen( theScript );
theObj = Tcl_NewUnicodeObj(theScript, returnLength );
Tcl_IncrRefCount(theObj);
Tcl_EvalObjEx(theInterp, theObj , TCL_EVAL_DIRECT );
Tcl_DecrRefCount(theObj);
}
Log in (anonymous is fine) to add a comment.