-
Notifications
You must be signed in to change notification settings - Fork 83
Closed
Labels
Description
There is a memory leak when using callbacks which take pointer arguments from native code to java in BridJ
When running the code below, instances of org.bridj.Pointer$OrderedPointer allocated by BridJ are never garbage collected eventually leading to out of memory. Using a callback which takes a non-pointer argument seems to work fine.
liblogger.h
typedef void (*CallbackType)(char*);
void callme(CallbackType);
void run();liblogger.c
#include "liblogger.h"
CallbackType logger;
void run() {
for(;;) {
logger("hello");
}
}
void callme(CallbackType cb) {
logger = cb;
}Main.java
import liblogger.*;
import org.bridj.Pointer;
public class Main {
public static void main(String[] args) throws Exception {
LibloggerLibrary.CallbackType callback =
new LibloggerLibrary.CallbackType() {
@Override
public void apply(Pointer<Byte> charPtr) {
}
};
LibloggerLibrary.callme(Pointer.pointerTo(callback));
LibloggerLibrary.run();
}
}