Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DragDropAction: Fix memory leak #1950

Merged
merged 5 commits into from
Jun 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/DragDropAction.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ namespace Gala {
}

public class DragDropAction : Clutter.Action {
private static Gee.HashMap<string,Gee.LinkedList<Actor>>? sources = null;
private static Gee.HashMap<string,Gee.LinkedList<Actor>>? destinations = null;
// DO NOT keep a reference otherwise we get a ref cycle
private static Gee.HashMap<string,Gee.LinkedList<unowned Actor>>? sources = null;
private static Gee.HashMap<string,Gee.LinkedList<unowned Actor>>? destinations = null;

/**
* A drag has been started. You have to connect to this signal and
Expand Down Expand Up @@ -120,10 +121,10 @@ namespace Gala {
Object (drag_type : type, drag_id : id);

if (sources == null)
sources = new Gee.HashMap<string,Gee.LinkedList<Actor>> ();
sources = new Gee.HashMap<string,Gee.LinkedList<unowned Actor>> ();

if (destinations == null)
destinations = new Gee.HashMap<string,Gee.LinkedList<Actor>> ();
destinations = new Gee.HashMap<string,Gee.LinkedList<unowned Actor>> ();

}

Expand Down Expand Up @@ -155,14 +156,16 @@ namespace Gala {
var dest_list = destinations[drag_id];
dest_list.remove (actor);
}

actor.destroy.disconnect (release_actor);
}

private void connect_actor (Actor actor) {
if (DragDropActionType.SOURCE in drag_type) {

var source_list = sources.@get (drag_id);
if (source_list == null) {
source_list = new Gee.LinkedList<Actor> ();
source_list = new Gee.LinkedList<unowned Actor> ();
sources.@set (drag_id, source_list);
}

Expand All @@ -172,12 +175,14 @@ namespace Gala {
if (DragDropActionType.DESTINATION in drag_type) {
var dest_list = destinations[drag_id];
if (dest_list == null) {
dest_list = new Gee.LinkedList<Actor> ();
dest_list = new Gee.LinkedList<unowned Actor> ();
destinations[drag_id] = dest_list;
}

dest_list.add (actor);
}

actor.destroy.connect (release_actor);
}

private void emit_crossed (Actor destination, bool is_hovered) {
Expand Down
Loading