Skip to content

Conversation

@sjorsdonkers
Copy link
Contributor

Before App.init would allocate it self on the heap (allocator).
However there appears to be no reason for it not to live on the stack.
This way the caller get's to decide.

@sjorsdonkers sjorsdonkers marked this pull request as ready for review March 28, 2025 10:53
}),
};
app.telemetry = Telemetry.init(app, config.run_mode);
app.telemetry = Telemetry.init(&app, config.run_mode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is taking a stack address. It could be ok, depending on what Telemetry does with the app, but in this case, it isn't.

The alternative to doing what I did is to have init take app *App, which achieves what you want: allowing the caller to decide where the app lives. Just a slightly less friendly API and, in many cases, just puts the heap allocation burden on the caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sjorsdonkers sjorsdonkers deleted the app_should_not_own_app branch March 28, 2025 11:57
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants