Skip to content
Tcl Source Code Artifact [db5e1d016d]
Login

Artifact [db5e1d016d]

Artifact db5e1d016d269be2c94a72da40f0b08e09c0d256:

Ticket change [db5e1d016d] - Ticket [781746ffffffffff|781746ffff] <i>Memory leak with arrays whose elements are lists</i> status still Pending with 7 other changes by msofer on 2003-08-02 05:37:44.
D 2003-08-02T05:37:44
J assignee msofer
J closedate 2003-08-01T22:37:44
J closer msofer
J icomment Logged\sIn:\sYES\s\nuser_id=148712\n\nThis\smay\snot\sreally\sa\sbug\sin\stcl,\sbut\srather\spilot\serror?\sOr\ninsufficient\sdocs?\sOr\sone\sof\sthose\scases\swhere\sknowledge\sof\nthe\sinternals\smakes\sa\sdifference\s(performance,\smemory).\n\nFirst,\snote\sthat\s\syour\sscript\sruns\smuch\sbetter\sif\syou\sreplace\s\n\s\s\s\sset\sa($count)\s[concat\s$element\s$count]\nin\sthe\screation\sloop\swith\sthe\stwo\slines\n\s\s\s\sset\sa($count)\s$element\n\s\s\s\slappend\sa($count)\s$count\nor\selse\swith\n\s\s\s\sset\sa($count)\s[concat\s$element\s[list\s$count]]\nNote\sthat\sthese\sare\s(in\sthis\scase)\sfully\sequivalent,\sexcept\nfor\sthe\smemory\srequirements.\n\nI'll\stry\sto\sexplain\sthe\sdifference\sin\smemory\srequirements,\nand\slet\syou\sdecide\swhere\sthe\sbug\sis.\n\nThe\sproblem\sis\scaused\sby\sthe\sfact\sthat\s[concat]\sreturns\sa\nnew\sTcl_Obj;\sif\sany\sof\sthe\slists\sto\sbe\sconcatenated\sis\s*not*\na\spure\slist\s(which\sis\syour\scase),\sa\sstring\srepresentation\sis\nreturned.\s\sYour\sscript\shence\sdefines\sall\sarray\selements\ninitially\sfrom\stheir\sstring\sinternal\srepresentation.\s\n\nThe\sfirst\sloop\sthen\sconverts\sa\scopy\s(recordLine)\sof\seach\n$a($count)\sto\sa\slist\swhen\srequesting\sits\sllength;\sbut\nrecordLine's\sis\spromptly\sdiscarded\sat\sthe\snext\siteration.\sSo\nyou\shave\s20000\sstring\sreps\sand\sone\slist\swith\s100\selements.\nThe\ssecond\sloop\sconverts\severy\sarray\selement\sto\slist\nrepresentation;\syou\shave\sthen\s20000\sTcl_Obj\sfor\sthe\n$a($count),\seach\swith\sboth\sa\sstring\sand\sa\slist\nrepresentation,\splus\s2000000\sTcl_Obj\sfor\sthe\selements\sof\n$a($count)\s...\sboom.\n\nSo:\swhy\sdoesn't\smy\slittle\schange\sboom\stoo?\sTcl's\sinternal\nare\sclever\sabout\ssharing\sTcl_Obj's\s-\sin\sthe\ssecond\sand\sthird\nversions,\sthe\score\srecognizes\sthat\smany\sof\sthose\s2000000\nelements\sare\srepeated,\sand\smanages\swith\s20000\sobjects\s(each\nwith\sa\sref\serence\scount\sof\s100)\sfor\sa\stotal\sof\s40000.\n\nBut\sthe\score\sis\snot\sclever\senough\sto\snotice\sthat\sthe\s2000000\nelements\scan\sbe\srepresented\sso\ssparingly\sin\syour\sscript,\nwhich\screates\sthem\safresh\sby\ssplitting\sthe\sstring\svalues\sof\nthe\s$a($count).\sMy\sversions\snever\sdestroyed\sthe\srelationship\nto\sbegin\swith,\syours\s"went\sout\sof\sits\sway"\sto\shide\sit.\s\n\nI\sdo\shope\sthe\sexplanation\sis\sunderstandable\s...\n
J login msofer
J mimetype text/plain
J username msofer
K 781746ffffffffffffffffffffffffffffffffff
U msofer
Z 7f9e29269ad26e1f89ae919bf85376c5