I'm using some third party source code, which is meant to be run with a GUI, but I'm integrating it without using the GUI, and I've noticed severe memory leaks from the third party code which I am using. So I'm wondering, would it be possible to somehow create an object of that third party application instance in something like a sandbox, where I could remove the object later and all the references to any objects that that code was calling would be removed by the garbage collector.
Is something like that possible? What alternatives are there to achieving a similar scenario or would like the only possibility be to call the other application from a process builder like java -jar customApp ...? That's a bit ugly though...
EDIT: Would running that code in a separate Thread and then wait for the thread to complete cause the garbage collector to remove all the objects related to what was called there?