Book a Demo

Author Topic: How to free memory consumed by EA...  (Read 4589 times)

chrvi

  • EA User
  • **
  • Posts: 75
  • Karma: +0/-0
  • There are so many hidden features...
    • View Profile
How to free memory consumed by EA...
« on: June 01, 2007, 06:40:29 am »
Hi,

today I include the exact source code I use. It might be easier for anybody to find out if I did anything wrong ;-)
The application is quite easy and the only thing it does is going through all the packages and their elements in EA and printing out the name of the object being processed.

Please, if anybody had any idea why EA doesn't free its memory (easily to see among processes in the Task Manager), let me know...

Java source:
Code: [Select]

public class EADirectProcessing {

 private Repository repository;
   
 public static void main(String[] args) {
     EADirectProcessing demo = new EADirectProcessing();
     demo.run(args);
 }
   
 private void run(String[] args) {
     repository = new Repository();
     repository.OpenFile("c:/test.eap");

     Collection<Package> models = repository.GetModels();
     if (models != null) {
       processPackages(models);
     }  

     repository.Compact();//try to free the consumed memory
     System.out.println("finished");
   }

   public final void processPackages(Collection<Package> packages) {
     int count = packages.GetCount();
     for (Package myPackage : packages){
       try {
         System.out.println("Package "+myPackage.getName());

         Collection<Element> elements = myPackage.GetElements();
         if (elements != null) {
           processElements(elements);
         }
         
         Collection<Package> subPackages = myPackage.GetPackages();
         if (subPackages != null)
           processPackages(subPackages);
         
         myPackage.destroy(); // try to destroy the processed COM object
         //myPackage = null; // I've tried it enabled, too
       } catch (Exception e){
         System.err.println("package error: "+e); // null
       }
     }
     packages.destroy(); // try to destroy the processed collection
     //packages = null;
     repository.Compact(); // has no effect
   }
   
   
   public final void processElements(Collection<Element> elements) {
     int count = elements.GetCount();
     for (Element myElement : elements){
       try {
           System.out.println("  Element "+myElement.getName());
           
           if (myElement.GetElements() != null) {
             processElements(myElement.GetElements());
           }
           
           myElement.destroy();
           //myElement = null;
       } catch (Exception e){
         System.err.println("element error: "+e); // null
       }
     }
     elements.destroy();
     //elements = null;
   }
     
}

=================
PS: This time (although the application consumes large amount of memory unwilling to free it again) the application ends with a serie of NullPointerExceptions (if my EA project is really huge).
I found out that in a certain moment (probably when a critical amount of memory has been consumed) each object begins to return null.
E.g. first six objects (of the total let's say eight objects) in a collection (let's say a collection of elements) have been processed. The amount of consumed memory reached the critical limit and all the following iterations (if I caught the exceptions a and let the program continue) in this collection will return null instead of the remaining objects.
Then the parent collection continues (elements were processed so the processing of packages (i.e. parent objects) continues with the next unprocessed package.
Again all the expected objects to be processed in the (packages) collection throw a NullPointerException instead of obtaining the correct object.
After the last exception thrown (and caught) the application finishes without processing lots of project objects (skipped due to all the nulls returned) and a vast amount of memory consumed.
« Last Edit: June 01, 2007, 07:02:59 am by chrvi »
Radek

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to free memory consumed by EA...
« Reply #1 on: June 03, 2007, 01:06:22 pm »
I don't know, but maybe your explicit calls to destroy is somehow bypassing Java releasing the COM objects.

chrvi

  • EA User
  • **
  • Posts: 75
  • Karma: +0/-0
  • There are so many hidden features...
    • View Profile
Re: How to free memory consumed by EA...
« Reply #2 on: June 04, 2007, 04:54:05 am »
At first I didn't try to destroy anything but EA consumed enormous amount of memory resources so I wanted to find a way to free it.

I tried to call repository.compact() but it had no effect.
Then I tried to call myObject.destroy() before repository.compact() but it still didn't help.
Finally I tried to set myObject to null to make sure that repository.compact() would succeed (since there shouldn't remain any reference to myObject then).
I must have tried everything but still no effect... :-(
« Last Edit: June 04, 2007, 08:03:08 am by chrvi »
Radek

chrvi

  • EA User
  • **
  • Posts: 75
  • Karma: +0/-0
  • There are so many hidden features...
    • View Profile
Re: How to free memory consumed by EA...
« Reply #3 on: June 05, 2007, 05:43:32 am »
I have noticed that you, Simon, are the author of classes in the eaapi.jar. So you're probably the best to ask...

Would you, please, tell me what exactly the someObject.destroy() does?
I can only see a native comDestructor(anObject) call but don't know anything more.

Does the destroy() method work correctly for you?

Have you ever watched the memory usage when working with EA through Java?

I believe my example code above is the most simple application where a growing up memory usage can be immediately seen (because of the recursion) even if the project isn't huge.
However, if you have a small project, you have to look at the memory usage before the application finishes (otherwise it simply finishes, EA process ends up correctly as well and the memory is freed)).

I wonder what your consumed memory would be if you tried my code yourself watching the memory behaviour...
« Last Edit: June 05, 2007, 11:51:38 pm by chrvi »
Radek

romkin

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: How to free memory consumed by EA...
« Reply #4 on: August 26, 2007, 01:12:49 pm »
Hi!

I'm having the same problem...
Chrvi, may be you have figured out some solution?
Any hint may be?

Thanks.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to free memory consumed by EA...
« Reply #5 on: August 26, 2007, 01:26:43 pm »
Hello Romkin,

The first thing to try would be upgrading your EA version to build 814.  With that, and periodically calling Repository.Compact() you shouldn't have any problems with memory usage of the Java API.