Skip to content

Fix leak on failure to load renderable#408

Merged
OneLoneCoder merged 1 commit into
OneLoneCoder:developfrom
Gusgo99:fix_leak_on_failure_to_load_renderable
Jun 22, 2025
Merged

Fix leak on failure to load renderable#408
OneLoneCoder merged 1 commit into
OneLoneCoder:developfrom
Gusgo99:fix_leak_on_failure_to_load_renderable

Conversation

@Gusgo99

@Gusgo99 Gusgo99 commented Jun 19, 2025

Copy link
Copy Markdown
Contributor

The line removed had it's return value discarded. The return value is an owning raw pointer to a sprite just created by the function, so discarding it caused a leak. This code was used to test it:

bool OnUserUpdate(float fElapsedTime) override {
  renderable.Load("invalid_image.png"); // Attempt to load image that doesn't exist

  return true;
}

Before the change, a slow but steady increase in memory would happen with the previous code. After letting it run for a few minutes, the program reached 500 MB of used memory. After the change, no such increase in memory, and the same program takes 95 MB no matter how long it ran for.

…ointer. This caused a leak when a Renderable which already has an image loaded tries to load an image, but fails to do so.
@OneLoneCoder OneLoneCoder merged commit e336eac into OneLoneCoder:develop Jun 22, 2025
@OneLoneCoder

Copy link
Copy Markdown
Owner

yeah good spot, i guess reset() would also be appropriate but yeah

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 this pull request may close these issues.

2 participants