Tcl Source Code

View Ticket
Login
Ticket UUID: 454273
Title: memory leak in regexp (tcl8.3.3)?
Type: Bug Version: None
Submitter: hemanglavana Created on: 2001-08-22 17:03:34
Subsystem: None Assigned To: nobody
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2001-08-23 00:41:38
Resolution: Invalid Closed By: hobbs
    Closed on: 2001-08-22 17:41:38
Description:
If the expression for regexp command is dynamically
generated
during runtime, then it causes a memory leak.  I am
attaching a simple script to reproduce the problem
(note that you will have to compile tcl with
TCL_MEM_DEBUG flag).

Here is the output of running the script on solaris2.6
platform:


godel:48> ./regexp.tcl
Tcl version: 8.3.3
==================
   Total       Total   Current   Current   Maximum  
Maximum
   Mallocs     Frees   Packets    Bytes    Packets   
Bytes 
   -------     -----   -------   -------   -------  
-------
     21494     14706      6788    348516      6874   
413408  Initial
     21709     14890      6819    353810      6874   
413408  count 10
     21855     15034      6821    353835      6900   
413408  count 9
     21999     15178      6821    353835      6902   
413408  count 8
     22143     15322      6821    353835      6902   
413408  count 7
     22287     15466      6821    353835      6902   
413408  count 6
     22475     15643      6832    358217      6902   
413408  count 5
     22666     15823      6843    362639      6913   
413408  count 4
     22854     16000      6854    367021      6924   
413408  count 3
     23042     16177      6865    371403      6935   
413408  count 2
     23229     16354      6875    375345      6946   
413408  count 1
godel:49> 

You will note that the current bytes (4th column)
remain constant for first five iterations, but
increases for the remaining iterations. The first 5
iterations use a constant string.

This looks like a memory leak to me. We are having this
leak in one of our tcl-based server. If I use "string
match ..." instead of regexp, the memory leak goes
away.

Hemang.
User Comments: hobbs added on 2001-08-23 00:41:38:
Logged In: YES 
user_id=72656

This is not surprising, and it isn't a mem leak.  Tcl 
caches the most recent *30* regexps per thread in an RE 
compile cache.  This allows Tcl to save on possible 
expensive RE compilation.  You should see this number go up 
until 30 iters have been hit, and then the old REs will get 
swapped out.  This number is a compiled in constant.

hemanglavana added on 2001-08-23 00:03:35:

File Added - 9851: regexp.tcl

Attachments: