Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory isn't freed after entity removal #245

Closed
redain opened this issue Mar 13, 2021 · 2 comments · May be fixed by #251
Closed

Memory isn't freed after entity removal #245

redain opened this issue Mar 13, 2021 · 2 comments · May be fixed by #251

Comments

@redain
Copy link

redain commented Mar 13, 2021

I noticed that memory consumption slowly growing over time in one of my prototypes. Seems like after entity removing memory consumption is not decreasing.
I was able to reproduce it in a fresh new crate as well with a following code:

use legion::*;

#[derive(Default, Clone, Copy)]
pub struct Dummy {
    pub field_1: u128,
    pub field_2: u128,
    pub field_3: u128,
    pub field_4: u128,
}

fn main() {
    let mut ecs = World::default();
    loop {
        let ids = ecs.extend([(Dummy::default(),); 100].to_vec()).to_vec();
        for id in ids.iter() {
            ecs.remove(*id);
        }
    }
}

clear() for the entire World doesn't help as well.
Note that call to len() method of the World returns correct number of entities (in the example above at the end of each loop iteration it will show 0), which means that removals were successful.
Was tested both on debug and release.
Legion version: 0.4.0
OS: Windows 10

@Rua
Copy link
Contributor

Rua commented Mar 20, 2021

This is typical for Rust's built-in types too. Vec will keep its allocation after you remove or clear. It only reduces the allocation if you call shrink_to or shrink_to_fit. Something like that could be added to World as well, which the user could then call periodically.

@redain
Copy link
Author

redain commented Mar 20, 2021

This is typical for Rust's built-in types too. Vec will keep its allocation after you remove or clear. It only reduces the allocation if you call shrink_to or shrink_to_fit. Something like that could be added to World as well, which the user could then call periodically.

If I remove items from Vec and add the same amount of items later, previously allocated memory will be reused and memory consumption will not grow - it will be constant for the same amount of items, but in case with removing and adding entities seems like memory is not reused and it's consumption is only growing with each add/remove iteration.

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

Successfully merging a pull request may close this issue.

2 participants