Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 1a93e6493e4dd1d0ecf61b4679aeea8d6583ef7c
Ticket: 218066ffffffffffffffffffffffffffffffffff
The necessary use of the 'unset' in a recursive call is not
User & Date: nobody on 2000-10-26 00:52:48
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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
    
  4. foundin changed to: "obsolete: 8.0.4"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to:
    The necessary use of the 'unset' in a recursive call is not 
    
  11. type changed to: "Bug"