GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 2:23 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Memory leak with glib2... help needed
PostPosted: Wed Apr 23, 2008 5:12 am 
Offline

Joined: Wed Apr 23, 2008 5:06 am
Posts: 2
hi,
I am writing a simple application to grab window_opened event, I wish to get an event every time a window gets opened on the system.
So I did,
WnckScreen *screen = wnck_screen_get(0);

g_signal_connect(screen, "window_opened", (GCallback)WindowOpenCallback, NULL);
from my thread in addition to init part.
Now, I am getting the desired results but problem is over a period of time the top shows memory increase for my program(increase in RES memory in chunks of 4k,8k,12k...)...
I tried looking for the things.
Please help me out if this is a known issue with any of the library.
Thanks in advance...
Regards,
Amit Sahrawat


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 23, 2008 1:27 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
What type of memory are you looking at? If you look at the wrong type of memory reading, it could appear as though your program is leaking when it is not. Could you post some code? But first, read this article on memory readings in Linux: http://virtualthreads.blogspot.com/2006 ... linux.html

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 4:35 am 
Offline

Joined: Wed Apr 23, 2008 5:06 am
Posts: 2
Nice Article with good explanation, Thanks

My code is like this,

void InitScreens()
{
WnckScreen *screen = wnck_screen_get(0);

//Connect a callback to the window opened event in libwnck
g_signal_connect(screen, "window_opened", (GCallback)WindowOpenCallback, NULL);

}

capture_main()
{
int argc = 1;
char **argv = (char**)malloc(sizeof(char*));

/* Initializing the mutex for window control*/
pthread_mutex_init(&window_mutex,NULL); /*This is relevant to my data structures */

pthread_mutex_init(&rsrpmutex,NULL);/*This is relevant to my data structures */

//Initialise GDK
gdk_init(&argc, &argv);

//Connect to every screen
InitScreens();

loop = g_main_loop_new(NULL, TRUE);
g_main_loop_run(loop);

free(argv);
argv=NULL;
}
Then I have the callback function,
where I get the windows name and prepare a list for the same.

After running this program and opening up windows very frequently, say around 4-5 windows every minute...
the TOP programs shows increase in RES memory for the program.


26248 root 18 0 124m 4712 3780 S 0.3 1.4 0:00.78 capture
26248 root 18 0 124m 4712 3780 S 0.3 1.4 0:00.79 capture
26248 root 18 0 124m 4712 3780 S 0.3 1.4 0:00.80 capture
26248 root 18 0 124m 4712 3780 S 0.3 1.4 0:00.81 capture
26248 root 18 0 124m 4720 3788 S 0.3 1.4 0:00.82 capture
26248 root 18 0 124m 4720 3788 S 9.6 1.4 0:01.11 capture
26248 root 18 0 124m 4720 3788 S 0.3 1.4 0:01.12 capture
26248 root 18 0 124m 4720 3788 S 0.7 1.4 0:01.14 capture
26248 root 18 0 124m 4720 3788 S 9.0 1.4 0:01.41 capture
26248 root 18 0 124m 4720 3788 S 1.3 1.4 0:01.45 capture
26248 root 18 0 124m 4720 3788 S 1.0 1.4 0:01.48 capture
26248 root 18 0 124m 4720 3788 S 11.7 1.4 0:01.83 capture
26248 root 18 0 124m 4720 3788 S 0.7 1.4 0:01.85 capture
26248 root 18 0 124m 4720 3788 S 0.7 1.4 0:01.87 capture
26248 root 18 0 124m 4724 3788 S 10.6 1.4 0:02.19 capture
26248 root 18 0 124m 4728 3788 S 9.6 1.4 0:02.48 capture
26248 root 18 0 124m 4728 3788 S 1.0 1.4 0:02.51 capture
26248 root 18 0 124m 4728 3788 S 0.3 1.4 0:02.52 capture
26248 root 18 0 124m 4728 3788 S 0.3 1.4 0:02.53 capture
26248 root 18 0 124m 4736 3788 S 9.3 1.4 0:02.81 capture
26248 root 18 0 124m 4736 3788 S 1.3 1.4 0:02.85 capture
26248 root 18 0 124m 4736 3788 S 0.3 1.4 0:02.86 capture
26248 root 18 0 124m 4736 3788 S 0.7 1.4 0:02.88 capture
26248 root 18 0 124m 4740 3788 S 5.3 1.4 0:03.04 capture
26248 root 18 0 124m 4740 3788 S 5.0 1.4 0:03.19 capture
26248 root 18 0 124m 4740 3788 S 0.3 1.4 0:03.20 capture
26248 root 18 0 124m 4740 3788 S 0.7 1.4 0:03.22 capture
26248 root 18 0 124m 4748 3788 S 4.3 1.4 0:03.35 capture
26248 root 18 0 124m 4748 3788 S 5.0 1.4 0:03.50 capture
26248 root 18 0 124m 4748 3788 S 0.3 1.4 0:03.51 capture
26248 root 18 0 124m 4748 3788 S 0.3 1.4 0:03.52 capture
26248 root 18 0 124m 4748 3788 S 0.3 1.4 0:03.53 capture
26248 root 18 0 124m 4748 3788 S 1.0 1.4 0:03.56 capture
26248 root 18 0 124m 4752 3788 S 6.7 1.4 0:03.76 capture
26248 root 18 0 124m 4752 3788 S 4.7 1.4 0:03.90 capture
26248 root 18 0 124m 4832 3868 S 1.0 1.4 0:03.93 capture

Regards,
Amit Sahrawat


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot], newguy, Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group