nativelibs4java / BridJ

BridJ: blazing fast Java / C / C++ interop
https://code.google.com/archive/p/bridj/
Other
299 stars 77 forks source link

Memory consumption by Pointer allocations. #27

Open ochafik opened 9 years ago

ochafik commented 9 years ago

From @haron4igg on May 27, 2013 20:26

Hi Olivier,

I'm working with continuos calculations, which producing a lot of double arrays from C library. Using BridJ caused to real memory consumption problem.

By VisualVM tool i figured out that all allocated and released pointers are still exist in memory and being garbaged only after manual invocation of GC.

Here it is my code, may be i did something wrong..:

NativeCalculatorLibrary.OutputCallback callback = new NativeCalculatorLibrary.OutputCallback() { @Override public void apply(double v, Pointer doubles, double v2) { if (doubles != null && listener != null) { double [] input = doubles.getDoubles(dimension); listener.onReceivePoints(v, input, v2); doubles.release(); } } };

I had a similar problem with JNI, but it was fixed by deleting local environment reference after performing callback.

Thank you in advance, Igor.

Copied from original issue: ochafik/nativelibs4java#404

ochafik commented 9 years ago

Hi @haron4igg,

Sorry for forgetting this issue, I believe it was a duplicate of #440, fixed 4 months after you filed this one. I'll make sure your use-case is fixed before closing.

Cheers