Reduce peak memory use #278
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During some operations there are some pretty large memory usage peaks.
When reloading a page from the menu there is a peak, but not when switching to another page. When reloading a page,
invalidatePages()
is called but there is nocollectgarbage()
as inincPage()
. Then we might have two copies of the same page loaded for a brief moment.Added
collectgarbage()
toinvalidatePages()
to deal with this.The second case is when selecting a page from the main menu. Here we also end up with two pages in memory. The script will load a page in the background and the main menu code will load a page when pressing enter.
Removed the page loading in the main menu code and replaced it with
invalidatePages()
which now also collects garbage. Then the page can be loaded by the code that is already in place to do it.I have done multiple tests with and without these changes. Now I'm seeing dips in memory use when selecting a page from the main menu. When reloading a page it's the same as when switching between pages. Opentx shows that free memory has increased by over 10kb