Memory and handle leak in SolidEdge when opening and closing parts?

Creator
Creator

I wonder if someone could test some code for me, please?

 

I have a process which needs to open a number of models and generate jpeg images of them (better quality than those imbedded in the file), but when run on models it appears Solid Edge does not properly release the memory, leaving me in a situation where the Edge.exe process is sitting at several gb of RAM usage and retaining 8000+ open handles.

 

Code is written in C++ as an AddIn. - Attached is a sample function which simply opens and then closes the same model 400 times.

 

I have tested this using both DocumentPtr->Close() and ApplicationPtr->Documents->DocumentClose(filename) and both appear to leak memory and/or handles.

 

My testing (today) has been using ST8 with MP01 applied.

 

Thanks,

Chris.


Chris Mann | Development Director
Concurrent Systems, Inc. Ltd.

http://www.csi-europe.com

29 REPLIES

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

Hello Chris,

 

did you already read Jason's blog entry about closing files?

 

http://community.plm.automation.siemens.com/t5/Solid-Edge-Developer-Blog/Closing-Documents/ba-p/3044...

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Creator
Creator

Wolfgang,

 

I have - that was one of the reasons I looked into our memory leak problem again!

Even with the new code, it still doesn't seem to free up properly (although it is slightly better in ST8 that in ST4 that we also need to be supporting our code against!)

 

Thanks,

Chris.


Chris Mann | Development Director
Concurrent Systems, Inc. Ltd.

http://www.csi-europe.com

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I haven't yet tested your code, but I know there might be some handles not being released immediately (like Wolfgang and Jason already mentioned)

Anyway, what you are going to do is a typical batch job, so you would write this normally in an external macro code, where you quit and restart SE after having processed, let's say 50 files (like the OpenSave macro from Siemens).

This will ensure that you don't run out of memory or any other resource handle count.

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Creator
Creator

Martin,

 

Thanks for the suggestion - for our import tools, we do exactly as you are suggesting - using an external app to start SE, process a series of models and restart SE every x number of files.  We implemented those tools in that method purely because of memory leaks in SE back at v20.

 

However, in this particular instance, the large assemblies we are working with require the action to be started by the user on the currently active assembly model and it's child components during part of a save routine within SE.

 

Thanks,

Chris.


Chris Mann | Development Director
Concurrent Systems, Inc. Ltd.

http://www.csi-europe.com

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

Hello Chris and Martin,

 

just another note to memory issues possibly not caused by Solid Edge only.

 

On feedback of one of my larger customers i can tell you that the memory leak behaviour seems obviously to also depend on some system/BIOS settings or capabilities of the PC platform being used. My customer, using my tool XProof which is drilling down the whole structure of an opened large assembly by opening, processing and closing all of its sub components too, could show to PC suppliers different behaviour of memory management of their platforms. One system reproducable freed up memory causing no problems at all, while another system ran into problems. All systems used operated on the same Windows and Solid Edge versions and had identical amount of RAM. Unfortunately i didn't get any detailed information and i couldn't proof it on my own.

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Out of curiosity, how are you verifying that Solid Edge is leaking memory and handles?

 

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Creator
Creator
Using either Task Manager and showing the Handles column or using Sysinternals ProcessExplorer and viewing the properties - performance information for the edge.exe process.

Chris Mann | Development Director
Concurrent Systems, Inc. Ltd.

http://www.csi-europe.com

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I created a StressTest sample on GitHub. The sample opens and closes files from the training folder. With this sample, I can confirm that the handle count continuously increases as the program executes. I tested using ST8. I suggest that you file an IR with GTAC with sample code to reproduce the issue.

 

HandleCount.jpg

 

Regarding the sample C++ code that you provided, my only comment is it looks like you're not releasing smart pointers as you should be. I'm not a C++ guru by any stretch of the imagination but my understanding is that you should assign a variable to each object\property and set it to NULL when you're finished.

 

GetApplicationPtr()->Documents

// should be

SolidEdgeFramework::ApplicationPtr pApplication = NULL;
SolidEdgeFramework::DocumentsPtr pDocuments = NULL;

pApplication = GetApplicationPtr();
pDocuments = pApplication->Documents;

// work with variables

pDocuments = NULL;
pApplication = NULL;

It's more code but like I said, my understanding is that this is the correct way to work with smart pointers.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Memory and handle leak in SolidEdge when opening and closing parts?

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

MartinBernhard wrote:

Anyway, what you are going to do is a typical batch job, so you would write this normally in an external macro code, where you quit and restart SE after having processed, let's say 50 files (like the OpenSave macro from Siemens).

This will ensure that you don't run out of memory or any other resource handle count.


Martin, I just wanted to share my thoughts on this approach. I've written many enterprise level batch processing applications that interact with Solid Edge and it is my experience that you cannot rely on "restart after n files". While that may work for simple parts, drafts, etc. I noted that processing large assemblies can easily cause this logic to fail. While I acknowledge that it's a workaround, my opinion is that it absolutely sucks to have to do it this way and it is unreliable and as such, cannot be relied upon as a solution. Just my opinion though.

 

p.s. Many kudos and thank you's for all of your extremely helpful answers. I personally appreciate the time you contribute answering questions and enjoy gleaning knowledge from your insights.

Jason Newell
Applications Architect
www.jasonnewell.net