Skip to content

Commit 6637d3d

Browse files
committed
nemo-action-manager.c: Don't randomize action names when rebuilding.
GtkAction names are 'interned' and never freed for the life of the process. For Nemo actions, the name (which is really an escaped url) is made 'unique' every time actions are reloaded, in order to avoid issues with the UI manager when editing the layout. When a lot of actions are in use, this can end up using a lot of memory over time as each instance of a GtkAction adds to Gtk's internal name list. Since this is all the fault of using a custom action layout, use part of that layout file's mtime to stamp each generation of actions. If this never changes for the life of the process (the user doesn't edit the layout), the internal action names will never change, and just be re-used.
1 parent d7e5b97 commit 6637d3d

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

libnemo-private/nemo-action-manager.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct {
3636

3737
GList *actions_directory_list;
3838
gboolean action_list_dirty;
39+
gint layout_timestamp;
3940
} NemoActionManagerPrivate;
4041

4142
struct _NemoActionManager
@@ -246,16 +247,18 @@ set_up_actions_directories (NemoActionManager *action_manager)
246247
}
247248

248249
static char *
249-
create_action_name (const char *uri)
250+
create_action_name (NemoActionManager *manager,
251+
const char *uri)
250252
{
253+
NemoActionManagerPrivate *priv = nemo_action_manager_get_instance_private (manager);
251254
GString *s;
252255
g_autofree gchar *prefix = NULL;
253256

254257
if (uri == NULL) {
255258
return NULL;
256259
}
257260

258-
prefix = g_strdup_printf ("action_%d_", g_random_int_range (0, 9999));
261+
prefix = g_strdup_printf ("action_%d_", priv->layout_timestamp);
259262
s = g_string_new (prefix);
260263

261264
while (*uri != 0) {
@@ -301,7 +304,7 @@ add_action_to_action_list (NemoActionManager *action_manager, NemoFile *file)
301304

302305
uri = nemo_file_get_uri (file);
303306

304-
action_name = create_action_name (uri);
307+
action_name = create_action_name (action_manager, uri);
305308
gchar *path = g_filename_from_uri (uri, NULL, NULL);
306309

307310
action = nemo_action_new (action_name, path);
@@ -361,6 +364,9 @@ static void
361364
reload_actions_layout (NemoActionManager *action_manager)
362365
{
363366
NemoActionManagerPrivate *priv = nemo_action_manager_get_instance_private (action_manager);
367+
GFile *file;
368+
GFileInfo *info;
369+
guint64 timestamp;
364370

365371
GError *error = NULL;
366372
g_autofree gchar *path = NULL;
@@ -380,11 +386,23 @@ reload_actions_layout (NemoActionManager *action_manager)
380386
}
381387
}
382388

389+
priv->layout_timestamp = 0;
383390
g_clear_error (&error);
384391
g_clear_object (&parser);
385392
return;
386393
}
387394

395+
file = g_file_new_for_path (path);
396+
info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL);
397+
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) {
398+
timestamp = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
399+
} else {
400+
timestamp = (guint64) (ABS (g_get_monotonic_time ()));
401+
}
402+
priv->layout_timestamp = (gint) (timestamp % 10000);
403+
g_object_unref (info);
404+
g_object_unref (file);
405+
388406
priv->json_parser = parser;
389407
DEBUG ("Loaded action layout file: %s\n", path);
390408
}

0 commit comments

Comments
 (0)