Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jun 21, 2024
1 parent 26bdef7 commit 667045f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Core/SearchEngine.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

public class AppCenterCore.SearchEngine : Object {
public ListModel results { get; construct; }
public ListModel results { get; private set; }

private ListStore packages;
private AppStream.Pool pool;
Expand Down Expand Up @@ -60,4 +60,14 @@ public class AppCenterCore.SearchEngine : Object {
this.category = category;
packages.items_changed (0, packages.n_items, packages.n_items);
}

/**
* This should be called if the engine is no longer needed.
* We need this because thanks to the delegates we get a reference cycle,
* where the filter and sorter keep a reference on us and we on them.
* Setting results to null will free them and they will in turn free us.
*/
public void cleanup () {
results = null;
}
}
4 changes: 4 additions & 0 deletions src/Views/SearchView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public class AppCenter.SearchView : Adw.NavigationPage {
});
}

~SearchView () {
search_engine.cleanup ();
}

private void on_items_changed () {
list_view.scroll_to (0, NONE, null);

Expand Down

0 comments on commit 667045f

Please sign in to comment.