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.

Is your feature request related to a problem? Please describe.

When I remove a Mesh I want to clean up everything that was created with it. So that means all materials and geometry which are part of the mesh.

Describe the solution you’d like

This is the implementation I’ve been using. This could be a separate class as shown below or better yet part of the base Mesh class so all types of Meshes could benefit from this.

class DisposableMesh extends Mesh {
    public dispose(): void {
        this.geometry.dispose();
        const materials = Array.isArray(this.material) ? this.material : [this.material];
        materials.forEach((material) => {
            material.dispose();
        });
        this.removeFromParent();
    }
}

Describe alternatives you’ve considered

The class shown above can easily be implemented in userland and repeated in each project that it is used.

Additional context

Since garbage collection cannot be automatic for these things, having a single easy way to remove everything is very helpful when you have scenes that are constantly creating and destroying objects.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mjurczykcommented, Aug 28, 2021

While, like probly everyone at some point, I also fought angrily against having to write disposing mechanics per-project - imo it’s still best to keep it out of three.

What would DisposableMesh do if other meshes reuse some / all its materials 🤔 ? What about texture disposal 🤔? What about material disposal, where material wasn’t reused but specific textures were 🤔?

In apps / demoscene it doesn’t really happen - but in games disposing reusable materials will result in constant recompilation stutter, and, effectively, death of the entire gamedev genre within approximately 3-4 workdays 💀

1reaction
Mugen87commented, Aug 28, 2021

That sounds correct. Also check out the related discussion at the forum. E.g.

https://discourse.threejs.org/t/when-to-dispose-how-to-completely-clean-up-a-three-js-scene/1549

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amazon.com: Mesh Postpartum Underwear 10 Counts C ...
Disposable mesh panties can provide convenience and comfort for your trip, period, pregnancy, and post-pregnancy. Disposable Postpartum Underwear for Women.
Read more >
Mesh Disposable Underwear - Walmart.com
Mesh Disposable Underwear(99) ; From $7.99 ; $15.66. current price $15.66 ; From $21.66 ; From $14.99 ; From $20.99.
Read more >
Postpartum Mesh Underwear | Disposable Knit Panties & ...
Postpartum Mesh underwear effectively holds pads and liners securely in place while providing a breathable, cloth-like outer fabric that conforms to the natural ......
Read more >
Disposable Mesh Pants | Incontinence Supplies
Lightweight pant with leak-proof pouch. Mesh covering and moisture-proof lining; May be positioned in pouch for male or female.
Read more >
Disposable Mesh Panty - ASP Medical
Designed to hold a liner in place when pants are sized correctly; Ideal for maternity use; Disposable mesh panties that are soft and...
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