Duet Memory Leak
JasonS
Posts: 229
Anybody have any tips on finding a memory leak in Duet? Talked to Tech Support and there does not seem to be any way to do a heap dump to try and figure out what objects are orphaned and not getting collected.
0
Comments
Are you try/catching all possible null pointer exceptions? People seem to think they aren't of much consequence but if they add up they can leak memory to trace them. I entered into a Java project where there was a method that built a interface from an XML file, and the text position attribute was wrong the whole way through the XML file, instead of 'center' it was 'middle' or vice versa so every time that attribute was accessed a null pointer exception occurred. They weren't catching the error, as the compiler doesn't enforce it, so they were never seen. Once that error was cleared up all sorts of problems went away including memory leaks. Java's stack trace system uses a lot of resources on its own. Just a thought, YMMV.
Paul
I think alot of my issue has been not removing listeners from OBjects before releasing them. I am also spawning and killing 10 Threads at a time to handle ip connections as I iterate thru a database of 200 sites. Kim Burgess's AMX Performance Monitor program has been invaluable in monitoring my Duet memory usage in real time. The two attachments show my before and after utput from AMX Performance Monitor so far. I am still not 100% comfortable with my programs behavior, I think that the garbage collector works in very mysterious ways.
This is considered bad form, so I'd suggest not doing it if it can be avoided, and it usually can. Its the equivalent of black tape over the engine light, and if you ignore exceptions and then get a lot of them, things can slow to a crawl and you won't have a clue why. Why torture your future self in this manner when it can be avoided? I typically check for all error states that I can preemptively and than catch any that I can't and do the correct thing. Sometimes there is nothing to be done so just an empty clause and a comment is appropriate, but I try to avoid that as much as possible especially in RTOS, and CPU intensive programs since Java's error checking is such a resource hog.
Paul
I try to catch any null pointer exceptions with "if ( != null)" before I use an Object. At this point in my experience level I would perfer slow operation to none. Hopefully I can improve that as I gain more experience. I am still not completely sure which of the modifications I made improved my Duet memory usage. I am still testing it, so I may break it yet! Thank you for your great pointers!
Can anyone confirm that this is true? I'm debugging a sticky issue with long-term crashes at the moment and would love to get some heap dumps, even if it's fiddly to do.