What am I doing wrong?
- From: Count Zero <countzero cyberdeck org>
- To: gtk-list gnome org
- Subject: What am I doing wrong?
- Date: 04 Jun 2000 12:41:03 CDT
Ok, thanks to Havok for his help with gtk_pixmap_get()
Here is my full problem:
First, some code:
struct pixmap_info {
GtkWidget *pixmap;
gchar *filename;
};
void reload_pixmap (struct pixmap_info *pixmap, gint data) {
GdkColormap *colormap;
GdkPixmap *gdkpixmap;
GdkBitmap *mask;
gchar *checked_filename;
colormap = gtk_widget_get_colormap (pixmap->pixmap);
/* does filename exist? */
checked_filename = check_file_exists(prefs.pixmapdir,
pixmap->filename);
if (!checked_filename) {
g_warning ("Pixmap file %s does not exist", pixmap->filename);
gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL,
colormap, &mask, NULL, dummy_pixmap_xpm);
} else {
gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL,
colormap, &mask, NULL, checked_filename);
if (gdkpixmap == NULL) {
g_warning ("Error loading pixmap file: %s",
checked_filename);
gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d
(NULL, colormap, &mask, NULL, dummy_pixmap_xpm);
}
}
gtk_pixmap_set ((GtkPixmap*)pixmap->pixmap, gdkpixmap, mask);
gdk_pixmap_unref (gdkpixmap);
gdk_bitmap_unref (mask);
g_free(checked_filename);
return;
}
Ok, this works great, I use it in conjunction with a GSList of pixmap_info
structures, and when a user switches themes I use g_slist_foreach() to call
reload_pixmap. Everything goes as planned, except that my memory usage seems
to creep up steadily (every time I switch themes, top shows a few more bytes
used by my program.) So I am thinking I have a memory leak here. I figured at
first that since I wasn't unref'ing the OLD gdkpixmap and mask that this was
the source of my memory leak, so I used gtk_pixmap_get() (thanks Havok) to pull
in the old gdkpixmap and mask, and then unref'ed them (to destroy them) But of
course I get
Gdk-CRITICAL **: file gdkpixmap.c: line 823 (gdk_pixmap_unref): assertion
`private->ref_count > 0' failed.
When I try that, showing me that gtk_pixmap_set() must automagically unref the
old gdkpixmap and mask.
So, what am I missing? or is the fact that a top shows a few bytes of increased
memory usage NOT an indication of a memory leak?
Please let me know if you need more info to help with this problem, or feel
free to point out that I am in idiot who should learn more about C before
attempting this kind of program (just not on the list please) Either way, any
comments (constructive prefered) are welcomed...
-Count Zero
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]