Skip to content
Tcl Source Code View Ticket
Login

View Ticket

The necessary use of the 'unset' in a recursive call is not

Closed / Invalid218066ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:52:48
OriginalBugID: 1557 RFE
Version: 8.0.4
SubmitDate: '1999-03-19'
LastModified: '2000-04-03'
Severity: LOW
Status: Closed
Submitter: pat
ChangedBy: hobbs
OS: Other
OSVersion: NT4.0, IRIX 6.2, IRIX 6.5, Mac OS8.1 & OS8.5
Machine: NA
FixedDate: '2000-10-25'
ClosedDate: '2000-04-03'


Name:
William Chen

DesiredBehavior:
    It appears that the garbage collection properties of Tcl+Tk does not
    extend to the "infinitely Recursive" calls.  Placing the recursive
    function call in an after script script is still recursion.  Memory has
    to be released by unsetting unused local variables.  Unless this local
    memory is released, it will never be released while the Wish Shell is
    running.
    
    I'm providing samples of two methods used to create event handlers.  The
    after command allows the separate polling event handlers to execute in
    different threads.  It is also more elegant than putting them all into
    one big while loop since multiple events can be polled at different
    intervals.
    
    Unset is only briefly mentioned on your web page.  Ousterhout's
    _Tcl_and_the_Tk_ToolKit_ and Welch's
    _Practical_Programming_in_Tcl_and_Tk_ books dedicate 1 small paragraph
    each to unset.
    
    ______________________________
    Function1 {} {
     global Function1ID
     Fucntion2
     set Function1ID [after _time_ Function1]
    }
    
    Function2 {} {
      global saveString
      local var1 var2 string1
      set var1 Somevalue
      set var2 Somevalue
      set string1 SomeLargevalueReturnedFromFunctionCall
    
      set saveString $string1  ;# copy local value to global
    
    #Local variables must be unset to release memory for recursive call
    #Normally Garbage Collection will take care of this.
    #We were not doing this before and it was causing memory leaks
      unset var1
      unset var2
      unset string1
    }
    
    KillFunciton1 {} {
       after cancel $Function1ID
    }
    
    _________________________________
    
    TestFunction {} {
      global TestFuntionID
      global saveString
      local var1 var2 sting1
      set var1 SomeValue
      set var2 SomeValue
      set string1 SomeLargeValueRetunedFromFunctionCall
    
      set saveString $string1 ;# copy local value to global
    
    #Local variables must be unset to release memory for recursive call
      unset var1
      unset var2
      unset string1
    
    #Make a recursive call to the function after a set time.
      set TestFunctionID  after _time_ TestFunction
    }
    
    KillTestFunction {} {
      after cancel $TestFunctionID
    }
    
    After calling KillTestFunction or KillFunction1, TestFuntion and
    Funtion1 does not know that the recursive call has been interrupted.
    The memory created withing these functions does not get released without
    an explicit call to unset them.
    




"local" isn't a Tcl core command, and it may not be coded correctly
to release the objects.  Otherwise, this doesn't seem like it should
be a problem in the core (Tcl tests Pure). 
-- 04/03/2000 hobbs
welch Closed ticket [218066ffff]. [History diff]2000-10-26 08:13:45
dgp Ticket [218066ffff]: 4 changes [History diff]2001-04-16 23:39:04
Log in (anonymous is fine) to add a comment.