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

Huge amount of data in vectors will not be released #13372

Closed
mlp1802 opened this issue May 14, 2024 · 4 comments
Closed

Huge amount of data in vectors will not be released #13372

mlp1802 opened this issue May 14, 2024 · 4 comments
Labels
C-Bug An unexpected or incorrect behavior S-User-Error This issue was caused by a mistake in the user's approach

Comments

@mlp1802
Copy link

mlp1802 commented May 14, 2024

Bevy version

0.13.2
The release number or commit hash of the version you're using.

`AdapterInfo { name: "NVIDIA GeForce RTX 2070", vendor: 4318, device: 7938, device_type: DiscreteGpu, backend: Vulkan }`

What you did

fn my_function()->Vec<BigStuff> {
    let big_stuff_vector:Vec<BigStuff> = create_stuff();
    vec![] //big_stuff_vector is never used 
}

Calling this function (only from a bevy context, a menu button for example) causes the "big_stuff_vector" to take up memory, even it is never being used.
It contains about 1-2 GB of fairly deeply nested structures. It contains no pointers or references, or anything else like that. Only standard bevy enums/structs. There is no global variables referencing any of it.
After running this code 3-4 times, the computer runs out of memory and crashes.

I found a workaround, by using "mimalloc" as global allocator. This however would not run without crash unless I disabled dynamic_linking in Cargo.toml, so not the best workaround.


## What went wrong
Computer runs out of memory

- workarounds that you used
Use "mimalloc" as global allocator and disable dynamic_linking in Cargo.toml

@mlp1802 mlp1802 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 14, 2024
@bushrat011899
Copy link
Contributor

Could you provide some additional information regarding the exact context you're using? For example, is this running inside a system?

use bevy::prelude::*;

fn my_function_that_causes_issues() { /* ... */ }

fn my_system() {
    let _ = my_function_that_causes_issues();
}

fn main() {
    App::new()
        .add_systems(Update, my_system)
        .run();
}

At a guess, it sounds like you might be storing highly fragmented data, making it (eventually) impossible to allocate your large structure. This video from fasterthanlime does a pretty good job of going over this particular type of issue.

As to why it's only present when run in a Bevy context: Bevy may be a sufficiently complex system that its allocations are hemming in your available chunks of memory.

@mlp1802
Copy link
Author

mlp1802 commented May 15, 2024

It's not running directly in a system, but a system calls the function. Thanks for the link, will investigate this further.

@mlp1802
Copy link
Author

mlp1802 commented May 15, 2024

So in any case, it's not a bevy thing, I'd assume.

@bushrat011899
Copy link
Contributor

I believe so. I suspect this is a more fundamental issue in your project that only exposes itself when run with Bevy (or a similar project).

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
@alice-i-cecile alice-i-cecile added S-User-Error This issue was caused by a mistake in the user's approach and removed S-Needs-Triage This issue needs to be labelled labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior S-User-Error This issue was caused by a mistake in the user's approach
Projects
None yet
Development

No branches or pull requests

3 participants