[Melbourne-pm] TK repeats, scoping and keeping track of objects

Toby Corkindale toby.corkindale at strategicdata.com.au
Mon Jan 12 18:30:45 PST 2009


Leigh Sharpe wrote:
> Hi Jacinta,
> 
> 
>> You can create an array of all the objects and then weaken those
> references so that the object will still be 
>> cleaned up upon going out of scope.  You then want to make sure that
> you handle holes in your array.  For 
>> example:
>  
> Thanks, that looks like the answer I'm after.
> 
> Perhaps, however, I didn't explain my problem clearly enough:
> 
>> Is there a reason you're not returning your object?  It seems odd to
> worry about whether objects can properly be 
>> cleaned up when going out of scope (as you mentioned above) and then
> not actually pass them back into the 
>> program so that you can use them in the scope for which you've created
> them.  
> 
> I am returning an object. The function I had in my original email was
> not in my package, it was in main. Here's a working example of what I'm
> experiencing:

[snip]
I note that the Tk docs state:
"Note however that while a window exists for $widget the perl object is 
maintained (due to "references" in perl/Tk internals) even though 
original variables may have gone out of scope. (Normally this is 
intuitive.)"

I suggest you look at the OnDestroy() callback instead of relying on the 
Perl garbage collection here.


-Toby


More information about the Melbourne-pm mailing list