Bug 6795 - Memory Leak in ModifyBg
Summary: Memory Leak in ModifyBg
Status: RESOLVED FIXED
Alias: None
Product: Gtk#
Classification: Mono
Component: gtk-sharp ()
Version: 2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-08-31 11:31 UTC by Elmar Haneke
Modified: 2016-11-18 16:38 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Elmar Haneke 2012-08-31 11:31:31 UTC
On Calling Widget.ModifyBg or Widget.ModifyBase there seems to be an
Memory-Leak

Reproducible: Always

The problem does assise within this code:

        public static void SetAllBG(int Farbe) {
            Gdk.Color c;
            if (Farbe>=0) {                        
                int r= Farbe      % 256;
                int g=(Farbe>>8)  % 256;
                int b=(Farbe>>16) % 256;
                c=new Gdk.Color((byte)r,(byte)g,(byte)b);
                foreach (Gtk.Window w in Gtk.Window.ListToplevels())
                    DoSetBg(w,c);
            } else {
                foreach (Gtk.Window w in Gtk.Window.ListToplevels())
                    DoResetBg(w);
            }
        }

        public static void DoResetBg(Gtk.Widget w) {
            /*
             * Hintergrundfarbe auf den Standardwert zurücksetzen
             */
            w.ModifyBg(StateType.Normal);
            w.ModifyBg(StateType.Prelight);
            w.ModifyBg(StateType.Insensitive);

            w.ModifyBase(StateType.Normal);
            w.ModifyBase(StateType.Prelight);
            w.ModifyBase(StateType.Insensitive);
            /*
             * Eventuelle untegeordnete Objekte ebenfalls bearbeiten
             */
            Gtk.Container ct=(w as Gtk.Container);
            if (ct!=null)
                ct.Foreach(DoResetBg);
        }

        public static void DoSetBg(Gtk.Widget w,Gdk.Color c) {
            /*
             * Farbwert für den Hintergrund eintragen
             */
            w.ModifyBg(StateType.Normal,c);
            w.ModifyBg(StateType.Prelight,c);
            w.ModifyBg(StateType.Insensitive,c);

            w.ModifyBase(StateType.Normal,c);
            w.ModifyBase(StateType.Prelight,c);
            w.ModifyBase(StateType.Insensitive,c);
            /*
             * Eventuelle untegeordnete Objekte ebenfalls bearbeiten
             */
            Gtk.Container ct=(w as Gtk.Container);
            if (ct!=null)
                foreach (Widget s in ct)
                    if (!(    (s is Entry) ||
                              (s is ComboBox) ||
                              (s is DatumEingabe) ||
                              (s is CheckButton) ||
                              (s is TreeView) ||
                              (s is TextView)
                    ))
                        DoSetBg(s,c);

        }
Comment 1 Marius Ungureanu 2016-11-18 16:38:37 UTC
This is fixed in newer gtk# 2.12 versions.