question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add the ability to clear all pools in Pools

See original GitHub issue

I think it would be useful to add the ability to clear all pools that are stored internally in Pools via the static variable typePools. The implementation seems to be rather straightforward: Simply iterate over all the pools and call their clear method. Something like this:

public class Pools {
    // ...
    public static void clear() {
        for (ObjectMap.Entry<Class, Pool> entry : typePools)  {
            entry.value.clear();
        }
    }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cypherdarecommented, Aug 30, 2020

I’m going to close this, as a valid use case that doesn’t abuse the handling of Disposables was never demonstrated. Disposables aren’t practical to place into ReflectionPools, as any of the libGDX classes implementing Disposable are unlikely to have a useful empty constructor and also be the sort of thing you need many of.

Suppose you want to pool Pixmaps or FrameBuffers. These don’t have useful empty constructors. You would need to make your own Pool that calls a specific constructor with specific parameters in newObject(). And then you can freeAll() your own pool when the game is disposed.

If a reflection-pooled class references Disposable objects that it does not own, it should null out the references in reset().

1reaction
cypherdarecommented, Aug 15, 2016

@asherbar, I think @xGnoSiSx was maybe assuming this clearing would be automatically done, which I don’t think you were suggesting.

Seems like since this is apparently the only use case, you’d actually want a clearDisposables method that clears only the objects that implement Disposable. The sample code you gave would result in leaking all Disposables. It should look something like this:

public static void clearDisposables() {
    for (ObjectMap.Entry<Class, Pool> entry : typePools)  {
        if (entry.key.isAssignableFrom(Disposable.class){
            Pool pool = entry.value;
            while (pool.getFree() > 0) ((Disposable)pool.obtain()).dispose();
        }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pool Flocculant: How Does It Work and Is It Better Than Pool ...
A fast-acting formula that drops cloudy water particles to the bottom of the pool so you can vacuum it out. Fast Floc will...
Read more >
Open Your Own Pool & Keep it Clean All Season - EASY TIPS
You can spend upwards of $500 to have your pool opened! See how I open my pool for $10 & share tricks to...
Read more >
How To Clear A Green Pool FAST | Swim University - YouTube
Is your pool water green? The good news is you don't have to drain your pool and start over to get rid of...
Read more >
How Do I Make My Pool Water Crystal Clear? - CMP
If the filter and circulation are working correctly, adding the proper amount of chlorine can clear a pool right up. Check out our...
Read more >
How to Manage Connection Pools for PostgreSQL Database ...
The Pool Name doesn't affect how your pool functions, but it must be unique and it cannot be edited once the pool is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found