By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,406 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Garbage collection and soft real-time apps

P: n/a
Before I get into the question -- I know .NET isn't the right solution for
this app but it's part of my clients requirements and writing this in C++
isn't an option. That being said -- my app is a stock ticker using the
managed DirectX libraries and the animation needs to be perfectly smooth.
Problem is that the garbage collector will kick in from time to time and
cause my render thread to miss a frame and makes it look like hell (even at
75 hz it's quite noticeable).

Is there any way to prevent managed code to not block on garbage collection?
I know this generally isn't a good idea but all my render thread is doing is
calling Device.Present -- all the other threads aren't critical and can be
suspended. Any ideas would be greatly appreciated.
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Oculus" <Oc****@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
Before I get into the question -- I know .NET isn't the right solution for
this app but it's part of my clients requirements and writing this in C++
isn't an option. That being said -- my app is a stock ticker using the
managed DirectX libraries and the animation needs to be perfectly smooth.
Problem is that the garbage collector will kick in from time to time and
cause my render thread to miss a frame and makes it look like hell (even
at
75 hz it's quite noticeable).

Is there any way to prevent managed code to not block on garbage
collection?
I know this generally isn't a good idea but all my render thread is doing
is
calling Device.Present -- all the other threads aren't critical and can be
suspended. Any ideas would be greatly appreciated.


I think the best you can do is minimize the impact of garbage collection
using a two-pronged approach.

First thing is to work hard to produce less garbage. The less garbage you
produce, the cheaper and less frequent collections are. Using structs,
pooling objects, minimizing string allocations, and reusing buffers can
dramatically reduce the amount of garbage generated by your application.

Second is be to collect on your own schedule. When you know there is
garbage and you have some time, force a collection. In a winforms app where
your appliction owns the whole process and all of the memory allocations,
you can figure out when and where to collect better than the garbage
collector. For a general purpose application it's not worth the trouble,
but when you can't afford those little pauses it can be.

David
Jul 21 '05 #2

P: n/a
Thanks,

We've actually done both of those things and really pared down our throwaway
objects. Still, a generation 0 garbage collection can take over 15ms which
is about all the time I have to swap backbuffers (we're pre-rendering
backbuffers to help alleviate the problem).

"David Browne" wrote:

"Oculus" <Oc****@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
Before I get into the question -- I know .NET isn't the right solution for
this app but it's part of my clients requirements and writing this in C++
isn't an option. That being said -- my app is a stock ticker using the
managed DirectX libraries and the animation needs to be perfectly smooth.
Problem is that the garbage collector will kick in from time to time and
cause my render thread to miss a frame and makes it look like hell (even
at
75 hz it's quite noticeable).

Is there any way to prevent managed code to not block on garbage
collection?
I know this generally isn't a good idea but all my render thread is doing
is
calling Device.Present -- all the other threads aren't critical and can be
suspended. Any ideas would be greatly appreciated.


I think the best you can do is minimize the impact of garbage collection
using a two-pronged approach.

First thing is to work hard to produce less garbage. The less garbage you
produce, the cheaper and less frequent collections are. Using structs,
pooling objects, minimizing string allocations, and reusing buffers can
dramatically reduce the amount of garbage generated by your application.

Second is be to collect on your own schedule. When you know there is
garbage and you have some time, force a collection. In a winforms app where
your appliction owns the whole process and all of the memory allocations,
you can figure out when and where to collect better than the garbage
collector. For a general purpose application it's not worth the trouble,
but when you can't afford those little pauses it can be.

David

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.