Re: Changing font colors on the fly == memory leak!
| From: | Brian A. Stumm | Date: | Wed, 04 Jan 2006 01:05:12 +0000 |
| Subject: | Re: Changing font colors on the fly == memory leak! | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-6499@lists.php.net to get a copy of this message | ||
On Tue, 3 Jan 2006, Scott Mattocks wrote:
> Brian Stumm wrote:
> >
> > I figured out the problem, below is the updated version of previous script
> > with no memory leaking.
>
> For those of us who are too blind to see the changes (and for those
> searching the archives later) can you please point out exactly what has
> changed between the two versions of the script?
I struggled with this for a while. I thought I took care of the problem
once but only *reduced* the rate of the leak. The original post I made was
at that stage. Basically it has to do with creating all your styles,
colors, what not in your widget setup stuff and reuse those items in the
function you added with the gtk::timeout_add. Originally (not represented
in either posted script) I had this stuff in the function
$green=&new gdkcolor('darkgreen');
$yellow=&new gdkcolor('darkgoldenrod');
At that point my app would take down a linux box with 256MB memory in less
than a day. The version represented in post # 1's code ate 40% of system
memory in 80 some hours.
In the 2 scripts posted the key is where this line of code is located.
$st1 = $st1->copy();
In version A the above line was in the function. In version B its outside
the function and re-used.
I believe it is true that php does not free memory until the script
completes so reusing things/widgets whenever possible can really help
reduce usage. At this point my app uses about 18Megs memory and can run
for at least 3 days with no perceived memory usage increase.