Re: [tcljava-user] (no subject)
Brought to you by:
mdejong
From: Mo D. <mo...@mo...> - 2008-09-24 19:30:37
|
Dan Diolosa wrote: > > Hi, > > > I am wondering why I need to "preserve" a TclList that I don't return > to TCL, nor need/use after the function returns. > > I am trying to return just one sub-list from a list of sub-lists. If > I have just a list of normal TclObjects I can return one item without > a problem. What is wrong with this: > Hi Dan It is kind of odd, and the way you are using the list object is kind of odd too. I am sure there is some reason for it in your code, but in this example you should be able to just set the interp result to list1 without having to create another container list. I don't see why your code would need to preserve() the "list" variable, but it would need to release it after the interp.setResult() call in order to avoid leaking memory. When a TclObject is created it should have a ref count of 0, if you then release() it is should then be deallocated. The safest thing to do is to preserve() the container list, and then release() it (which will release any contained objects) after the interp.setResult() call. The release should be in a finally block, in case an exception is thrown. I hope that helps Mo DeJong |