For anyone uses StaticResource/DynamicResource, be aware of memory leak.

719 views
Skip to first unread message

Zhou Yong

unread,
Oct 8, 2008, 11:38:11 PM10/8/08
to wpf-di...@googlegroups.com
This is one of the most hidden aspect of WPF, pay attention to it:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b97a5f83-5394-430e-9a78-9d3a957e3537/

Yong

Marlon Grech

unread,
Oct 9, 2008, 3:38:02 AM10/9/08
to wpf-di...@googlegroups.com
does that happen only with a page object ?
Do you know what is the cause of such a thing?

Zhou Yong

unread,
Oct 9, 2008, 4:18:06 AM10/9/08
to wpf-di...@googlegroups.com
It happens if you create another window, and have StaticResource points to a app level resources.

This is a generic bug actually, I've forgotten the real cause of it, but windbg+SOS with !gcroot command should be enough to figure out what's going on:)

So be aware of StaticResource/DynamicResource, and remember to clear them out when the Page/Window instance is no longer needed by subscribing to Unloaded event, I know Unloaded event is not stable, but unfortunately, this is the  "only" solution I can think of.

Yong

Andrew

unread,
Oct 9, 2008, 8:26:20 AM10/9/08
to wpf-di...@googlegroups.com
I posted a workaround to the problem as well as a description of what's going on. Basically the objects referring to that resource are holding onto a ResourceReferenceExpression that is hooked into the Inflated clr event of the DeferredResourceReference, which is something that a ResourceDictionary hands out to refer to an item in the dictionary that hasn't been hydrated/created.

Laurent Bugnion

unread,
Oct 9, 2008, 8:36:07 AM10/9/08
to wpf-di...@googlegroups.com
Wow. I think I got it :) I love the visuals popping in my head, of
resources being hydrated and inflating.

--
Laurent Bugnion [Microsoft MVP, MCP]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Marlon Grech

unread,
Oct 9, 2008, 10:03:31 AM10/9/08
to wpf-di...@googlegroups.com
WOW Andrew... you really know this shit inside out....

Zhou Yong

unread,
Oct 9, 2008, 10:21:48 AM10/9/08
to wpf-di...@googlegroups.com
Cool trick Andrew,

I just wanna know if the framework has any mechanism to revert back to deferred state for resources when a specified resource item is no longer used by any elements?

Yong

Andrew

unread,
Oct 9, 2008, 10:41:45 AM10/9/08
to wpf-di...@googlegroups.com
Thanks but I just used a profiler and read the code in reflector. No magic here. :-)

Andrew

unread,
Oct 9, 2008, 10:46:01 AM10/9/08
to wpf-di...@googlegroups.com
I'm not aware of a case where it reverts back to a deferred state (but that doesn't mean they don't to it). Really its just a method of conserving memory - don't create objects until they're actually used. You wouldn't normally want to do this but as a workaround for this case it may be better than having to deal with it on the unload from the objects that use the resources.

----- Original Message ----
From: Zhou Yong <footb...@gmail.com>
To: wpf-di...@googlegroups.com
Sent: Thursday, October 9, 2008 10:21:48 AM
Subject: [WPF Disciples] Re: For anyone uses StaticResource/DynamicResource, be aware of memory leak.

Karl Shifflett

unread,
Oct 9, 2008, 8:50:22 PM10/9/08
to wpf-di...@googlegroups.com

Looking for a way to render a gradient along a circular path.

 

Example.  If you had a Rectangle and set the Background to a linear gradient, the colors would flow from left to right.

 

Now think of a short long Rectangle (10 X 300), now wrap the two ends together forming a doughnut shape and the gradient still flows from start to finish.

 

Any ideas?

 

Cheers,

 

Karl

FYI:  I just got another PET scan result from my doctor for my cancer.  Doc says I’m doing good.

Zhou Yong

unread,
Oct 9, 2008, 10:24:29 PM10/9/08
to wpf-di...@googlegroups.com
I also want to know how to achieve this type of things:) note that custom brush is still not supported in the current version of WPF, probably it will be introduced into the VNext by leveraging pixel shader:)

Yong

Pavan Podila

unread,
Oct 9, 2008, 10:32:42 PM10/9/08
to wpf-di...@googlegroups.com
This is exactly what I talked about with the PathGradientBrush. Your case is to use a circular path geometry for the brush's gradient flow. Wish there were a PathGradientBrush.


On Thu, Oct 9, 2008 at 10:24 PM, Zhou Yong <footb...@gmail.com> wrote:
I also want to know how to achieve this type of things:) note that custom brush is still not supported in the current version of WPF, probably it will be introduced into the VNext by leveraging pixel shader:)

Yong



--
the approach, rather than the solution
...o0O0o...
http://blog.pixelingene.com

Karl Shifflett

unread,
Oct 9, 2008, 10:38:05 PM10/9/08
to wpf-di...@googlegroups.com

Pavan,

 

Thank you.  I’m firing up Blend right now!

 

Cheers,

 

Karl

Pavan Podila

unread,
Oct 9, 2008, 11:36:36 PM10/9/08
to wpf-di...@googlegroups.com
Karl,
             If you don't need that to be a vector, you could also do the same in Illustrator and export as PNG. This is only if you don't need it to be a vector. Its tricky to get that gradient in WPF as of today.


BTW, I had skipped your part about the PET scan. Hope its all good Karl. Best Wishes.

Karl Shifflett

unread,
Oct 9, 2008, 11:55:45 PM10/9/08
to wpf-di...@googlegroups.com

Pavan,

 

Thank you.  20 months in remission.  It’s all good.

 

k-dawg

Corrado Cavalli

unread,
Oct 10, 2008, 12:22:29 AM10/10/08
to wpf-di...@googlegroups.com

>FYI:  I just got another PET scan result from my doctor for my cancer.  Doc says I’m doing good.

This is a great new! Well done Karl.

 

Corrado

 

 

From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On Behalf Of Karl Shifflett


Sent: venerdì 10 ottobre 2008 02:50
To: wpf-di...@googlegroups.com

Marlon Grech

unread,
Oct 10, 2008, 3:23:15 AM10/10/08
to wpf-di...@googlegroups.com
Great news Karl.... we are all with you :)

Sacha Barber

unread,
Oct 10, 2008, 3:53:41 AM10/10/08
to wpf-di...@googlegroups.com
Karl

Thats great news about the scan...Your VB .NET must be considered very important by the powers above. The earth needs more K-Dawg.




Date: Fri, 10 Oct 2008 09:23:15 +0200
From: marlo...@gmail.com
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: Does anyone know how to render a gradient along a path?

Try Facebook in Windows Live Messenger! Try it Now!

Laurent Bugnion

unread,
Oct 10, 2008, 3:54:30 AM10/10/08
to wpf-di...@googlegroups.com
That's great Karl. I am sure your positive uptake on life has a huge
effect on it. Keep smiling.

Laurent

Karl Shifflett wrote:
>
> Pavan,
>
> Thank you. 20 months in remission. It’s all good.
>
> k-dawg
>

> *From:* wpf-di...@googlegroups.com
> [mailto:wpf-di...@googlegroups.com] *On Behalf Of *Pavan Podila
> *Sent:* Thursday, October 09, 2008 8:37 PM
> *To:* wpf-di...@googlegroups.com
> *Subject:* [WPF Disciples] Re: Does anyone know how to render a

> gradient along a path?
>
> Karl,
> If you don't need that to be a vector, you could also do the same in
> Illustrator and export as PNG. This is only if you don't need it to be
> a vector. Its tricky to get that gradient in WPF as of today.
>
>
> BTW, I had skipped your part about the PET scan. Hope its all good
> Karl. Best Wishes.
>
>
> On Thu, Oct 9, 2008 at 10:38 PM, Karl Shifflett <ka...@littlerichie.com
> <mailto:ka...@littlerichie.com>> wrote:
>
> Pavan,
>
> Thank you. I'm firing up Blend right now!
>
> Cheers,
>
> Karl
>

> *From:* wpf-di...@googlegroups.com
> <mailto:wpf-di...@googlegroups.com>
> [mailto:wpf-di...@googlegroups.com
> <mailto:wpf-di...@googlegroups.com>] *On Behalf Of *Pavan Podila
> *Sent:* Thursday, October 09, 2008 7:33 PM
> *To:* wpf-di...@googlegroups.com
> <mailto:wpf-di...@googlegroups.com>
> *Subject:* [WPF Disciples] Re: Does anyone know how to render a

> gradient along a path?
>
> This is exactly what I talked about with the PathGradientBrush. Your
> case is to use a circular path geometry for the brush's gradient flow.
> Wish there were a PathGradientBrush.
>
> On Thu, Oct 9, 2008 at 10:24 PM, Zhou Yong <footb...@gmail.com
> <mailto:footb...@gmail.com>> wrote:
>
> I also want to know how to achieve this type of things:) note that
> custom brush is still not supported in the current version of WPF,
> probably it will be introduced into the VNext by leveraging pixel shader:)
>
> Yong
>
>
>
>
> --
> the approach, rather than the solution
> ...o0O0o...
> http://blog.pixelingene.com
>
>
>
>
> --
> the approach, rather than the solution
> ...o0O0o...
> http://blog.pixelingene.com
>

--

Karl Shifflett

unread,
Oct 10, 2008, 6:35:49 AM10/10/08
to wpf-di...@googlegroups.com
Thanks every for your support and encouragement! Wooo Hoooooooo! Let's
write some code!

Marlon Grech

unread,
Oct 10, 2008, 7:03:48 AM10/10/08
to wpf-di...@googlegroups.com
ROCK ON BOY!!!!!!!!!!
Reply all
Reply to author
Forward
0 new messages