simple wpf illustration causes rash memory growth


i have boiled down an emanate i'm observant applications an impossibly rudimentary mock-up sample. i need know there's something erroneous something i'm missing.



anyway, next code. function formula runs usually grows memory until crashes an outofmemoryexception. takes while, nonetheless function objects being allocated being rubbish collected.



i've taken memory dumps ran !gcroot things good used ants figure out problem is, nonetheless i've during while need new eyes.



this mock-up illustration rudimentary console concentration creates house adds line it. does continually. formula does. sleeps each again pledge cpu taxed your component nonchalant (and pledge there's weirdness gc being means run).



anyone have any thoughts? i've attempted .net 3.0 only, .net 3.5 also .net 3.5 sp1 same function occurred 3 environments.



also note i've put formula wpf concentration digest good triggered formula symbol click occurs there too.




using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.windows.controls;
using system.windows.shapes;
using system.windows;

namespace simplestreprosample
{
category program
{
[stathread]
stationary vacant main(string[] args)
{
enlarged count = 0;
while (true)
{
(count++ % 100 == 0)
{
// snooze while pledge aren't controlling adult whole cpu
system.threading.thread.sleep(50);
}
buildcanvas();
}
}

[system.runtime.compilerservices.methodimpl(system.runtime.compilerservices.methodimploptions.noinlining)]
private stationary vacant buildcanvas()
{
house c = new canvas();

line line = new line();
line.x1 = 1;
line.y1 = 1;
line.x2 = 100;
line.y2 = 100;
line.width = 100;
c.children.add(line);

c.measure(new size(300, 300));
c.arrange(new rect(0, 0, 300, 300));
}
}
}


note: initial answer next bit off-base given i definitely staid already same function occurs during wpf application's symbol click event. i definitely state, however, that app i wholly unparalleled array iterations (say 1000). doing proceed grant gc run click around application. also note i definitely conspicuous i've taken memory dump found objects secure around !gcroot. i also remonstrate gc means run. gc does run console application's sure thread, generally given i'm twin core accessory means indicate workstation gc active. summary pump, however, yes.



to infer point, here's wpf concentration chronicle runs exam dispatchertimer. performs 1000 iterations during 100ms timer interval. some-more adequate slight any messages out siphon keep cpu use low.




using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.windows;
using system.windows.controls;
using system.windows.shapes;

namespace simplereprosamplewpfapp
{
open biased category window1 : window
{
private system.windows.threading.dispatchertimer _timer;

open window1()
{
initializecomponent();

_timer = new system.windows.threading.dispatchertimer();
_timer.interval = timespan.frommilliseconds(100);
_timer.tick += new eventhandler(_timer_tick);
_timer.start();
}

[system.runtime.compilerservices.methodimpl(system.runtime.compilerservices.methodimploptions.noinlining)]
vacant runtest()
{
(int i = 0; i < 1000; i++)
{
buildcanvas();
}
}

[system.runtime.compilerservices.methodimpl(system.runtime.compilerservices.methodimploptions.noinlining)]
private stationary vacant buildcanvas()
{
house c = new canvas();

line line = new line();
line.x1 = 1;
line.y1 = 1;
line.x2 = 100;
line.y2 = 100;
line.width = 100;
c.children.add(line);

c.measure(new size(300, 300));
c.arrange(new rect(0, 0, 300, 300));
}

vacant _timer_tick(object sender, eventargs e)
{
_timer.stop();

runtest();

_timer.start();
}
}
}



note2: i used formula initial answer memory grew unequivocally slowly. note 1ms many slower reduction iterations example. have let run integrate mins before start notice growth. after 5 mins it's during 46mb starting indicate 30mb.



note3: stealing .arrange totally eliminates growth. unfortunately, graceful vicious given cases i'm formulating png files house (via rendertargetbitmap class). but .arrange doesn't plans house during all.



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members