Skip to content
Tcl Source Code Artifact [9ba84f713f]
Login

Artifact [9ba84f713f]

Artifact 9ba84f713faa12071d57be52d123edd353d7a63e:

Ticket change [9ba84f713f] - New ticket [218378ffffffffff|218378ffff] <i>memory leak in regsub</i>. by nobody on 2000-10-26 00:56:52.
D 2000-10-26T00:56:52
J assignee nobody
J cmimetype text/plain
J comment OriginalBugID:\s4333\sBug\nVersion:\s8.3\nSubmitDate:\s'2000-03-07'\nLastModified:\s'2000-03-21'\nSeverity:\sSER\nStatus:\sClosed\nSubmitter:\stechsupp\nChangedBy:\sericm\nOS:\sAll\sUnix\nFixedDate:\s'2000-10-25'\nClosedDate:\s'2000-03-21'\n\n\nName:\nDave\sDykstra\n\nReproducibleScript:\nI\skept\sparing\sdown\smy\scode\sto\sthe\sfollowing\stest\sscript.\s\sWhile\srunning\stclsh,\sin\sanother\nwindow\sdo\sa\sshell\sloop\srunning\sps\s-l\son\sthe\sprocess\severy\ssecond\sor\stwo\sto\swatch\sthe\sprocess\nsize\sexpansion.\s\sIt\sdoes\snot\shappen\swith\stclsh8.0.\s\sI\shave\sobserved\sthe\sgrowth\son\ssolaris,\shp,\sand\namdahl's\sUTS.\s\sThe\s"after"s\sare\sin\sthere\sto\sallow\stime\sfor\sps\sto\snote\sthe\sprocess\ssize.\n\n-----------------------\nafter\s3000\nputs\s"initializing"\nlappend\ssubs\s{^lib\\/toolman\\/.*}\nlappend\ssubs\s{^adm\\/rug\\/local\\/.*}\nlappend\ssubs\s{^\\.[^\\/]*_time$}\nlappend\ssubs\s{^\\.nsb_[^\\/]*$}\n\nfor\s{set\sn\s0}\s{$n\s<\s13}\s{incr\sn}\s{\n\s\s\s\sforeach\ssub\s$subs\s{\n\s\s\s\s\s\s\s\s\s\s\s\slappend\ssubs\s"^x/[string\srange\s$sub\s1\send]"\n\s\s\s\s}\n}\n\nputs\s"done\swith\ssetting\sup\ssubs"\nafter\s3000\nputs\s"calling\sregsub\son\s'nonmatch'\swith\s[llength\s$subs]\ssubstitutions"\nset\spath\s"nonmatch"\nforeach\ssub\s$subs\s{\n\s\s\s\s\s\s\s\sregsub\s-all\s--\s$sub\s$path\s""\spath\n}\nputs\s"path\sis\sstill\s$path"\nafter\s3000\nputs\s"done"\n\nObservedBehavior:\nProcess\ssize\sgrows.\n\n\n\nMemory\smanagement\sin\sTcl\sis\sa\sbit\sof\sa\stricky\ssubject.\s\sOne\simportant\sbit\s(important\sfor\sthis\sdiscussion\sanyway)\sis\sthat\sall\sliterals\sare\sstored\sin\sa\sglobal\sliteral\stable.\s\sThis\senables\sbetter\sperformance\sat\sthe\scost\sof\smore\smemory\susage.\n\nAnother\simportant\sbit\shas\sto\sdo\sspecifically\swith\sregular\sexpressions.\s\sWhen\sa\sregular\sexpression\sis\screated,\sit\shas\sto\sbe\s"compiled"\sfrom\sthe\sstring\srepresentation\sof\sit.\s\sThis\scan\sbe\scompute-intensive,\sso\sin\sorder\sto\sfurther\senhance\sperformance,\sthe\scompiled\srepresentation\sof\sa\sregular\sexpression\sis\scached,\sso\sif\sthe\sregexp\sis\sused\sagain,\sTcl\scan\savoid\srecompiling\sit.\n\nI\sbelieve\sthat\swhat\syou\sare\sseeing\shere\sis\sthe\sgrowth\sof\sthe\sglobal\sliteral\stable,\sand\sthe\screation\sof\smany\scompiled\sregular\sexpression\sobjects.\s\sHere's\sa\sbreakdown\sof\swhat\sis\shappening:\n\n1.\s\sEach\slappend\ssubs\screates\san\sentry\sin\sthe\sglobal\sliteral\stable.\s\sThis\nentry\sis\sa\sstring\sobject.\s\sThis\scauses\ssome\smemory\sallocation.\n\n2.\s\sEach\stime\syou\scall\sregsub\swith\sone\sof\sthose\sliterals,\sthe\sobject\sin\sthe\sglobal\sliteral\stable\sthat\sis\sassociated\swith\sit\sgets\schanged\sto\sa\sregexp\sobject.\s\sThis\scauses\ssome\sadditional\smemory\sallocation.\n\nIf\syou\swere\sto\slater\sgo\sback\sand\sforce\sthe\sobjects\sassociated\swith\sthose\sliterals\sto\sbe\sconverted\sto\ssome\snon-regular\sexpression\sobject\s(for\sexample,\sby\sdoing\s[llength]\son\sit),\sthe\scompiled\sregular\sexpression\sbits\swould\sbe\sfreed.\s\sBe\saware\sthat\sif\syou\stry\sthis\syou\smay\snot\sactually\ssee\sthe\smemory\sfootprint\sof\syour\sapplication\sdecrease;\salthough\sTcl\sis\sfreeing\sthe\smemory,\sthe\sOS\smay\snot\sactually\sreclaim\sit\suntil\sit\sneeds\sto.\s\sThis\swas\sthe\scase\son\smy\sLinux\smachine.\n\nIn\sshort,\sthis\sis\sthe\sexpected\sbehavior\sof\sthe\sinterpreter.\s\sThe\sprocess\sis\sgrowing\sbecause\sthe\sglobal\sliteral\stable\sis\sgrowing.\s\sYou\scan\stry\sto\savoid\sthis\sby\savoiding\sliteral\sexpressions\sand\sinstead\susing\scomputed\svalues.\n\n-\seric\n\n--\s03/21/2000\sericm\n\n
J foundin obsolete:\s8.3
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 69.\sOther
J title memory\sleak\sin\sregsub
J type Bug
K 218378ffffffffffffffffffffffffffffffffff
U nobody
Z 16bf47a43729cd73eecc189ef330a4fc