EnableThemingInScope not being removed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm having trouble with memory runaway and after using .NET Memory Profiler,
I'm finding the class SafeNativeMethods.EnableThemingInScope has instances
allocated frequently while not being removed.

This is in UI app with multiple forms available to be selected via a
toolbar.

How can I ensure that these instances are collected by the GC?
 
EChang,

How are you seeing runaway? They are not collected by the GC if
references are held to them. If they are around, it is because something is
holding them.

What is holding them?
 
Thx for the response.

Just by keeping Task Manager open I can see the total memory usage of the
app increasing until I get stack overflow errors.

My problem is that I do not even know where these instances are being
allocated. If I knew that, then I might know how to remove the references
keeping it allocated.

I found something helpful online however, though I do not fully understand
it.

"If you look at the samples that ship with the managed dx sdk, you will
notice that they use Application. DoEvents to drive the app. In the effect
editor, I was seeing objects of type EnableThemingInScope that were created
in something called by Application.DoEvents that weren't behaving as short
lived objects, they were surviving GCs. I spoke with the Windows.Forms guys,
asked them about this behavior and they told me that this was a heavyweight
API and that I shouldn't be using it for this purpose. They suggested hooking
up to the OnIdle event and checking the message queue with an unmanaged API
until they provide something like IsIdle()."

From:
http://www.xplsv.com/blogs/devdiary/2003_06_01_archive.html

I don't understand what a heavyweight API is. Also, Application.DoEvents is
called so that while something in my code is processing, other events can be
handled. I still want that functionality in my app. How can I keep
Application.DoEvents but not have the problems with instances of
EnableThemingInScope eventually killing my app?


Nicholas Paldino said:
EChang,

How are you seeing runaway? They are not collected by the GC if
references are held to them. If they are around, it is because something is
holding them.

What is holding them?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

EChang said:
I'm having trouble with memory runaway and after using .NET Memory
Profiler,
I'm finding the class SafeNativeMethods.EnableThemingInScope has instances
allocated frequently while not being removed.

This is in UI app with multiple forms available to be selected via a
toolbar.

How can I ensure that these instances are collected by the GC?
 
Stack overflow has nothing to do with GC, objects are NOT stack allocated.
SafeNativeMethods.EnableThemingInScope is not a class it's a method, so how
can you even see instances of it?
Your problem is mostly due to uncontrolled (or infinite) recursion.

Willy.

EChang said:
Thx for the response.

Just by keeping Task Manager open I can see the total memory usage of the
app increasing until I get stack overflow errors.

My problem is that I do not even know where these instances are being
allocated. If I knew that, then I might know how to remove the references
keeping it allocated.

I found something helpful online however, though I do not fully understand
it.

"If you look at the samples that ship with the managed dx sdk, you will
notice that they use Application. DoEvents to drive the app. In the effect
editor, I was seeing objects of type EnableThemingInScope that were
created
in something called by Application.DoEvents that weren't behaving as short
lived objects, they were surviving GCs. I spoke with the Windows.Forms
guys,
asked them about this behavior and they told me that this was a
heavyweight
API and that I shouldn't be using it for this purpose. They suggested
hooking
up to the OnIdle event and checking the message queue with an unmanaged
API
until they provide something like IsIdle()."

From:
http://www.xplsv.com/blogs/devdiary/2003_06_01_archive.html

I don't understand what a heavyweight API is. Also, Application.DoEvents
is
called so that while something in my code is processing, other events can
be
handled. I still want that functionality in my app. How can I keep
Application.DoEvents but not have the problems with instances of
EnableThemingInScope eventually killing my app?


Nicholas Paldino said:
EChang,

How are you seeing runaway? They are not collected by the GC if
references are held to them. If they are around, it is because something
is
holding them.

What is holding them?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

EChang said:
I'm having trouble with memory runaway and after using .NET Memory
Profiler,
I'm finding the class SafeNativeMethods.EnableThemingInScope has
instances
allocated frequently while not being removed.

This is in UI app with multiple forms available to be selected via a
toolbar.

How can I ensure that these instances are collected by the GC?
 
Back
Top