On Mon, 9 Oct 2000, Hollister, Jim wrote:

> When I use TclBlend to create and subsequently destroy Itcl objects I get a
> memory growth problem. If I do the same operation without TclBlend no growth
> occurs.
> 
> Here's my baseline Tcl-only script that doesn't cause the Tcl shell to grow
> in (memory) size:
> 
> package require Itcl 3.0
> 
> ::itcl::class TestClass {}
> 
> proc createAndDelete {} {
>       set d [TestClass ::#auto]
>       ::itcl::delete object $d
> }
> 
> set iterations 10000000
> for {set i 0} {$i < $iterations} {incr i} {
>       createAndDelete
> }
> 
> Here's a Java class that performs the same createAndDelete operation:
> 
> import tcl.lang.*;
> 
> public class MemTest {
> 
>       protected Interp myInterp = null;
> 
>       public MemTest(Interp interp) {
>               myInterp = interp;
>       }
> 
>       public void createAndDelete() throws TclException {
>               myInterp.eval("set d [TestClass ::#auto]");
>               myInterp.eval("::itcl::delete object $d");
>       }
> }
> 
> And here's the Tcl script that uses TclBlend to create the Java object and
> call it's createAndDelete method:
> 
> package require java 1.2.6
> package require Itcl 3.0
> 
> ::itcl::class TestClass {}
> 
> set memtest [java::new com.kla_tencor.catalyst.MemTest [java::getinterp]]
> 
> set iterations 10000000
> for {set i 0} {$i < $iterations} {incr i} {
>       $memtest createAndDelete
> }
> 
> When I run this TclBlend version the Tcl shell uses ever increasing amounts
> of memory. The combination of versions I'm using are:

Well, the createAndDelete() Java method is going to need to do some
work to parse the Java String objects you send to the interp and
then eval them. Each time eval is called, a copy of the Java
String object is going to be made. It should later get
garbage collected, but in a tight loop your Java app may
just keep allocating memory without collecting it. In your
Tcl example, nothing gets reparsed because the Tcl proc
gets compiled and then called N number of times.

Is the amount of memory used turning out to be a big problem?
Have you profiled it with a Java memory tracing tool?

Mo DeJong
Red Hat Inc

----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com

Reply via email to