ReflectionPool - static reference loss on Android?

Anything libgdx related goes here!

Re: ReflectionPool - static reference loss on Android?

Postby graham01 » Wed Apr 17, 2019 4:57 pm

Yea, so after playing with this some more, it seems like this is a problem with object initialization that I don't currently know how to get around cleanly. Take the following for example, as this is much more relevant to my problem;

Code: Select all
    public static class TestObject {
        final Image image;

        public TestObject(){
            image = new Image(LeakyPoolsTest.texture);
            image.setPosition(100, 100);

    private Stage stage;

    private static Texture texture;

    private TestObject object1;

    public void create() {

        stage = new Stage();

        Pixmap pixmap = new Pixmap(100, 100, Pixmap.Format.RGBA8888);

        texture = new Texture(pixmap);

        object1 = Pools.obtain(TestObject.class);



    public void render() {;

    public void dispose(){;

Okay, static Texture = bad. But it is created in create() and disposed in dispose(), so it shouldn't be a problem right? If I want to initialize anything in a pooled object that uses data outside the object, it must be fetched statically as it has to be initialized in a default constructor. Now I could have a set() method in my TestObject, that will re-apply the correct texture, and then I could do;

Code: Select all
TestObject object = Pools.obtain(TestObject.class);

But I feel it's cleaner if objects manage their own state. What I think is missing to be honest if libgdx is happy to reuse objects from previous instances, is a Poolable.obtained() method, much like the Poolable.reset(), so at least any broken references can be reformed if necessary.
Posts: 202
Joined: Thu Jul 09, 2015 4:53 am

Re: ReflectionPool - static reference loss on Android?

Postby evilentity » Wed Apr 17, 2019 5:36 pm

Clear the pool in create() and pretend the past didnt happen.
Looking for a freelancer? PM me!
Check out libgdx discord server!
Posts: 4727
Joined: Wed Aug 24, 2011 11:37 am


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest