Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Memory leak #77

Open
THEREALWWEFAN231 opened this issue May 1, 2022 · 1 comment
Open

Memory leak #77

THEREALWWEFAN231 opened this issue May 1, 2022 · 1 comment

Comments

@THEREALWWEFAN231
Copy link

So it appears there is a memory leak with DatabindJavascriptMethodHandler.Data. I have some javascript that is ran "every frame"

setInterval(() => {
    isEnabled = module.isEnabled();
  }, 0);

the module instance is retrieved from java.importClass. Of course setInterval isn't ideal, but I need to pass data over and it changes constantly. The setInterval function is called A LOT, are are more then 50 instances of it. But it just shows the problem.
Untitled

There are lots of DatabindJavascriptMethodHandler.Data instances being created every second but they are never deleted?

@THEREALWWEFAN231
Copy link
Author

I found another example. That's easier to understand.

This goes in onWindowReady

JavascriptClassDefinition oneClassDef = new JavascriptClassDefinition().name("one").attributes(JavascriptClassAttributes.NO_AUTOMATIC_PROTOTYPE);
			JavascriptClass oneClass = oneClassDef.bake();
			JavascriptObject oneObject = context.makeObject(oneClass);
			globalObject.setProperty("one", oneObject, 0);

			JavascriptClassDefinition twoClassDef = new JavascriptClassDefinition().name("two").parentClass(oneClass).attributes(JavascriptClassAttributes.NO_AUTOMATIC_PROTOTYPE);
			JavascriptClass twoClass = twoClassDef.bake();
			JavascriptObject twoObject = context.makeObject(twoClass);
			oneObject.setProperty("two", twoObject, 0);

			JavascriptClassDefinition threeClassDef = new JavascriptClassDefinition().name("three").parentClass(twoClass).attributes(JavascriptClassAttributes.NO_AUTOMATIC_PROTOTYPE);
			threeClassDef.onCallAsFunction(new JavascriptObjectFunction() {

				@Override
				public JavascriptValue callAsJavascriptFunction(JavascriptContext context, JavascriptObject function, JavascriptObject thisObject, JavascriptValue[] arguments) throws JavascriptInteropException {
					if (true) {
						JavascriptValue string = context.makeString("[{\"x\":-156.5,\"z\":265.5,\"type\":5},{\"x\":-158.5,\"z\":265.5,\"type\":5},{\"x\":-152.5,\"z\":267.5,\"type\":5},{\"x\":-160.5,\"z\":267.5,\"type\":5},{\"x\":-148.5,\"z\":267.5,\"type\":5},{\"x\":-150.5,\"z\":267.5,\"type\":5},{\"x\":-160.5,\"z\":265.5,\"type\":5},{\"x\":-154.5,\"z\":267.5,\"type\":5},{\"x\":-154.5,\"z\":265.5,\"type\":5},{\"x\":-152.5,\"z\":265.5,\"type\":5},{\"x\":-150.5,\"z\":265.5,\"type\":5},{\"x\":-158.5,\"z\":267.5,\"type\":5},{\"x\":-171.31021364279692,\"z\":240.2766290600617,\"type\":0},{\"x\":-162.5,\"z\":265.5,\"type\":5},{\"x\":-156.5,\"z\":267.5,\"type\":5},{\"x\":-148.5,\"z\":265.5,\"type\":5},{\"x\":-155.44999998807907,\"z\":272.44999998807907,\"type\":3},{\"x\":-162.5,\"z\":267.5,\"type\":5},{\"x\":-242.5,\"z\":242.5,\"type\":4}]");
						//string.contextUnlocking();
						return string;
					}
					return context.makeBoolean(false);
				}
			});
			JavascriptClass threeClass = threeClassDef.bake();
			JavascriptObject threeObject = context.makeObject(threeClass);
			twoObject.setProperty("three", threeObject, 0);

this exaggerates the memory leak, calls one.two.three a crap ton and task manager shows memory increasing by about 150MB per second. Looking at VisualVM shows that all objects java side are being correctly garbage collected. There must be something natively that is not releasing some memory?

 function update() {
    for (let index = 0; index < 2500; index++) {
        // @ts-ignore
        let f = one.two.three("");
        // @ts-ignore
        let f1 = one.two.three("");
        // @ts-ignore
        let f2 = one.two.three("");
      }
  }

 function animationFrame() {
    update();
    requestAnimationFrame(animationFrame);
  }
  requestAnimationFrame(animationFrame);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant