Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: localhro2 on February 09, 2016, 06:20:28 am
-
I create a java program that iterates through a selected EA model transforming classes from one modeling standard to another. The program copies the elements in the old standard and then creates the same elements in the new standard. To do this there are a lot of collections called, elements created, and iterations through the model. I continually max out the javaw.exe memory around 1.5 gb. Since I can't use any more memory than this, my program fails.
I know in the past the EA Java API had troubles with memory not freeing up, so I am manually calling
System.gc();
System.runFinalization();
in many parts of my code to try and clean out the unused elements. This doesn't seem to help at all.
I am also trying to destroy unused objects. After each collection is done being used I am manually calling .destroy() to try and free up the memory. Again this does not help at all.
What am I doing wrong? In much older posts from 2007, I see a Repository.Compact() recommeneded, but that method does not seem to exist any more. Any ideas or guidance would be appreciated.
Thanks,
Sean Conway
719-351-4544
-
Hi Sean,
Have you considered switching to C#?.
I have the feeling that that is a much better choice if you are going to use the API of Enterprise Architect.
It seems that the Java adapter is some kind of a crutch that only sorta works.
I know that's not the answer you are looking for, but there is not that much people that use Java for these purposes anymore.
Geert
PS. I don't think Repository.Compact would do you any good anyhow. I think it only compacted the actual .eap file
-
Thanks for the quick reply Geert. I like the idea of switching over to C#, but are you sure I won't run into this same problem?
What development environment would you recommend for C#? I have the free visual studio will that suffice for Sparx EA API Development?
Thanks,
Sean Conway
-
What am I doing wrong? In much older posts from 2007, I see a Repository.Compact() recommeneded, but that method does not seem to exist any more. Any ideas or guidance would be appreciated.
I haven't cross checked, but repository.compact was most likely just what you do with Manage .EAP Files/Compact from the menu.
q.
-
Sean,
You can create and build add-ins with Visual Studio Express, but debugging is a bit harder because it doesn't support "attach to process".
I use the free open source #develop (http://www.icsharpcode.net/) for all my add-ins, and I now prefer that IDE over VS.
If you need more info on developing add-ins in C# you can read more at: http://bellekens.com/writing-ea-add-ins/ (http://bellekens.com/writing-ea-add-ins/)
Geert
-
Geert,
I translated all of the code into C#, and now I keep getting a:
Exception thrown: 'System.Runtime.InteropServices.COMException' in JCA_Transform_Master.exe
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in JCA_Transform_Master.exe
Additional information: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
Pretty much EA crashes at random spots during the iterative Transform resulting in the com error above. Have you ever seen this? I don't see any reason that EA should be crashing and like I said it is random the element is always different that it chokes on. Any ideas would be appreciated.
Do I need to put timeouts in my code to ensure EA has enough time to complete actions? I'm running on a fast box Windows 7 with 32 GB RAM.
Thanks,
Sean Conway
-
No, not really.
Is it always at the same point in the code EA crashes?
if you post that part I might be able to help
Geert
-
Geert,
Another note: Could this be related to the latest Windows 7 Update? I swear this code had no issues until I got the latest Windows 7 push on Wednesday last week. Could that mess up the COM API for EA or is that out of the questions?
The code fails in completely random areas each time while trying to create diagrams or add objects to a diagram for example:
Collection conceptualDiagrams = newConceptualPackage.Diagrams;
Diagram newConceptualDiagram = conceptualDiagrams.AddNew(faceSDMObs.Name, "Conceptual");
Console.WriteLine("Created a Conceptual Diagram " + newConceptualDiagram.Name);
newConceptualDiagram.Update();
Collection newDiagramObjects = newConceptualDiagram.DiagramObjects;
DiagramObject fObsDiaObject = newDiagramObjects.AddNew("l=200;r=320;t=20;b=140", "");
fObsDiaObject.ElementID = faceSDMObs.ElementID;
Console.WriteLine("Created a Conceptual Diagram Object " + faceSDMObs.Name);
fObsDiaObject.Update();
Thanks,
Sean Conway
-
I'm not sure, I never had issues like that with any of my code (and I'm also on the last windows v7).
To be sure you could uninstall and re-install EA.
The only difference I see is that I usually have my code run as an add-in rather than as a standalone application.
Looking a the code snippet you posted I cannot see anything wrong.
Have you tried contacting support?
Geert
-
So I think I narrowed the problem code down to this line:
Collection allElements = repo.GetElementSet(null, 0);
I was calling this at the beginning of the tool to get a collection of classes with a specific stereotype. After removing this in favor of iterating through each package in the model looking for elements, EA stopped crashing.
Any ideas on why this call would not immediately cause a crash but instead cause a crash later in the program at a random spot?
Thanks
Sean Conway
-
Hi Sean,
EA.Collections are weird things and to be avoided as much as possible.
You can't avoid them completely of course, but as soon as I have a EA.Collection I put it into a regular collection.
Iterating EA.Collections does not do what you expect from iterating a collection in memory. Depending on what is actually stored in the collection it even sometimes goes to the database. So I put the elements in a regular collection (e.g. List<> ) as soon as I can and then iterate the regular collection.
Repository.GetElementSet() is very useful when combined with an SQL query. It will get a collection of element is a fraction of the time it takes to iterate the whole model package by package.
Geert