views:

117

answers:

2

We have a project where a 3rd party DLL is accessed through JacoZoom in a Tomcat application. Apparently the DLL leaks memory (confirmed by the vendor), but the vendor has no intention to fix this. The memory leak forces Tomcat to be restarted at regular intervals, which is naturally a great inconvenience for the users.

What would be the best way to work around this problem? One option we consider is having two instances of the Tomcat server and regularly restarting the other one, and redirecting the user to the other one.

Edit: solved by creating another DLL which kills and recreates the vendor DLL when needed. Basically these three kernel32 calls were used to accomplish the functionality:


Private Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleW" (ByVal DllName As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Luckily the JacoZoom JAR file doesn't seem to mind that the DLL is killed and recreated.

+4  A: 

I'm assuming that obvious things like "don't use that DLL" aren't on the table.

Can you create a wrapper, service, or layer around the crappy DLL that can be managed and restarted independently, and have Tomcat / Jacozoom / whatever call that service instead? In a sense, moving the memory leak to some other application outside the container?

Mikeb
Not using the DLL is not an option.. :) Creating an extra wrapper could be a viable alternative, bit more elegant that the crude Tomcat solution mentioned in the question.
simon
+2  A: 

I think Mike's suggestion of using a wrapper is the only way for you to go really.

You could write a COM server that hosts the 3rd party control and access it from your application. The wrapper process would still of course leak but you could arrange it such that it exits when there are no outstanding references to the hosted library.

You could also potentially use tools like LeakDiag to see if you can figure out where the leaks are coming from and try to persuade your reluctant vendor to play ball.

[Edit: exists->exits - Thanks Mark.]

Paul Arnold
+1. Typo? When there are no outstanding references it "exits" rather than "exists"
MarkJ