From Newsgroup: comp.lang.tcl
On 05/03/2025 21:41, abu wrote:
This works as expected (return 100.0), but if called 100.000 times,
I see an abnormal growth in memory (Megabytes).
What's wrong ?
For one thing, your reference count on resultObj is too high. You did an explicit Tcl_IncrRefCount() and Tcl_SetObjResult() increments it again.
It now has a count of 2. When the code that invoked the cfun command is
done with the result, it lowers the reference count by one. But that
does not free the Tcl_Obj, because it still has a reference count of 1.
As a Tcl_Obj takes 24 bytes on a 32-bit system (and more on a 64-bit
system), this would add up to a few megabytes when called 100.000 times.
Either skip the Tcl_IncrRefCount() and run Tcl_SetObjResult() before the Tcl_DecrRefCount() on aList, or do a Tcl_DecrRefCount() on resultObj
after the Tcl_SetObjResult() call.
Schelte.
--- Synchronet 3.20c-Linux NewsLink 1.2