0

My title may not make sense which is probably why I can't find a solution to the problem. I am lacking the vocabulary to properly search for it. Basically my problem is that I am implementing a c++ class with some virtual functions in Java through JNI. This works fine except for the fact that the parameters that are passed into the virtual function create new java objects each time and fill up the garbage collector.

class b2ContactListener
{
public:
    virtual ~b2ContactListener() {}

    /// Called when two fixtures begin to touch.
    virtual void BeginContact(b2Contact* contact){}
};

As you can see the BeginContact method has the parameter b2Contact *. In Java this creates a new Contact object everytime the virtual method is called. Is there a way to simply pass a reference to Java through JNI? Even if you can give me the term I'm looking for that would be great.

NJGUY
  • 2,045
  • 3
  • 23
  • 43
  • 1
    Post your JNI code, and the Java declarations of your native methods. Parameters do not create Java objects. *You* create Java objects. – user207421 Oct 08 '14 at 00:01
  • Also, please explain what you mean by "fill up the garbage collector" and how you've come to measure that. – Tom Blodget Oct 09 '14 at 01:45
  • Sounds like you're looking for something similar to http://stackoverflow.com/a/9889597/168175. Either that or declare `BeginContact` to take a `jobject` argument from C++ (but leave it as `b2Contact` in Java) and then manually create one and only one instance for all the calls you dispatch. – Flexo Oct 12 '14 at 02:44

0 Answers0