Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Memory Leak

Moderators: kris

Posted: 05/30/08 05:06:34

Having a memory leak I think its in Locale or WallClock? since the print function isn't leaking else where

Leaking

parent.print(27, 9, (new Locale)("{:hh:mm:ss tt}", WallClock.now));
parent.print(43, 28, (new Locale)("{:ddd, MMM dd, yyyy}", WallClock.now));

Not Leaking

parent.print(5, 1, sprint("{}", data.ENVTemp));
parent.print(145, 1, sprint("{}", data.GPUTemp));

Any Suggestions?

-Byron

Author Message

Posted: 05/30/08 07:41:21

what is it that indicates there's a leak? Note that Locale is currently rather resource hungry :)

Posted: 05/30/08 16:25:12

I had left the program running, (left to go watch Indian Jones Movie) came back and it had crashed.. so I re ran watch it in task manager it goes from 5k to 50k in a few mins.. I comment out these two lines and the memory usage stays constant....

Is there a less resource intense way to get the local date and time? This program prints to the G15 keyboard....

Posted: 05/30/08 17:48:47

That's interesting, and it would be good to get to the bottom of it. More likely to be Locale rather than WallClock, since the latter is not performing heap allocation that I'm aware of.

For lightweight time/date formatting, may I point you toward tango.text.convert.TimeStamp or tango.time.ISO8601 ?

Posted: 05/30/08 20:07:42

Ended up writing my own timeStamp function.. this test programs laid out to emulate the program I'm writing. In this demo deleting t and d didn't matter, but in my program it slowly eats memory if I don't.. not sure if the GC isn't triggering or if its cause its deep inside a threaded class..

But I'm not seeing any leaks now.

module test;

import tango.text.convert.Sprint;
import tango.time.WallClock;
import Util = tango.text.Util;
                
import tango.io.Stdout;

Sprint!(char) sprint;

void main()
{
	sprint = new Sprint!(char);
	
	while(true)
	    func;
}

void func()
{
	char[] t,d;
	timeStamp(t,d);
		
	Stdout.formatln("{}\n{}",t,d);

	delete t;
	delete d;
}

void timeStamp(out char[] t, out char[] d)
{
    static char[][] Months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", 
			      "Aug", "Sep", "Oct", "Nov", "Dec"];
    static char[][] Days   = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];	
    static char[][] AM     = ["AM", "PM"];
    auto c = WallClock.toDate;      
    
    t = sprint("{:d2}:{:d2}:{:d2} {}", 
     	(c.time.hours > 12 ? c.time.hours - 12 : c.time.hours), c.time.minutes, 
       	c.time.seconds, AM[c.time.hours > 12]).dup;

    d = sprint("{}, {} {:d2}, {:d4}", Days[c.date.dow], 
       	Months[c.date.month-1], c.date.day, c.date.year).dup;        
}