Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: chrvi on May 29, 2007, 01:37:51 am

Title: Destructing COM objects and freeing memory?
Post by: chrvi on May 29, 2007, 01:37:51 am
Hi there,

once again the question of memory lacks when using automation and Java...

I've just installed the new Enterprise Architect (6.5.805)and started using the eaapi.jar and SSJavaCOM.dll files.

I have a package and I wish to add subpackages as follows:

Collection<Package> subPackages;
subPackages = myPackage.GetPackages();
for (...) {
 newPackage = subPackages.AddNew("Package Name","foo");
    // by the way - what is the second parameter good for?
 newPackage.Update();
 subPackages.Refresh();
}

Now I'm going to process another package and add subpackeges to it in the same way, so I'd like to destroy the existing subPackages COM object since I won't need it any more (EA project has already been updated with the inserted subPackages in the for cycle above) and free the consumed memory.
I tried this:

subPackages.destroy();
subPackages = null;
repository.Compact();

The subPackages COM object was probably destroyed succsessfully, its number set to 0, then I set subpackages to null and called repository.Compact() but the memory usage didn't change at all.
I'm quite desperate 'cause my large model will consume all the memory resources unless I find out how to explicitely free memory at desired places in my code.