Skip to content

Conversation

@mikke89
Copy link
Owner

@mikke89 mikke89 commented Oct 5, 2024

Instead, explicitly start lifetime of globals on library initialization. This is achieved by using the new ControlledLifetimeResource class. This can be used as a wrapper around globals to explicitly initialize and shutdown the objects.

This wrapper has been applied to all non-trivial global data in RmlUi. Thus, there should no longer be any memory allocations occurring before main() when linking in RmlUi.

We now give a warning if there are objects in user space that refer to any RmlUi resources at the end of Rml::Shutdown, as this prevents the library from cleaning up memory pools. Other than the warning, the behavior should be the same as previously.

Breaking change: Rml::ReleaseMemoryPools is no longer exposed publicly. This function is automatically called during shutdown and should not be used manually.

Instead, explicitly start lifetime of globals on library initialization. This is achieved by using the new ControlledLifetimeResource class. This can be used as a wrapper around globals to explicitly initialize and shutdown the objects.

This wrapper has been applied to all non-trivial global data in RmlUi. Thus, there should no longer be any memory allocations occurring before `main()` when linking in RmlUi.

We now give a warning if there are objects in user space that refer to any RmlUi resources at the end of `Rml::Shutdown`, as this prevents the library from cleaning up memory pools. Other than the warning, the behavior should be the same as previously.

Breaking change: `Rml::ReleaseMemoryPools` is no longer exposed publicly. This function is automatically called during shutdown and should not be used manually.
@mikke89 mikke89 added enhancement New feature or request build Build system and compilation labels Oct 5, 2024
@mikke89 mikke89 linked an issue Oct 6, 2024 that may be closed by this pull request
@Paril
Copy link
Contributor

Paril commented Oct 10, 2024

Hey mikke! Thanks for looking into this.

I will attempt to get this tested on the specific platform we had issues with this weekend and will let you know what issues I run into.

@mikke89 mikke89 merged commit 41e1291 into master Oct 19, 2024
@mikke89
Copy link
Owner Author

mikke89 commented Oct 19, 2024

Thanks for testing the PR, since it seems to be working for you I am merging it as is.

@mikke89 mikke89 deleted the no-global-allocations branch April 26, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Build system and compilation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce the amount of static initialization in the library

3 participants