Sign in to follow this  
mrmrcoleman

Releasing DirectX components...

Recommended Posts

I just need to clarify what happens, with regards to memory, when I release a DirectX object. Here's an example... In my program I have a full screen 60mb AVI which I play at the beginning of the application. When this loads up I can see, in Windows Task Manager, that Direct Show is loading approx 15mb of this into memory. However when I release all the DirectShow interfaces this does not go down again. I was under the impression that if I released all the components DirectShow would free up memory for me... Is this incorrect? Also, I will shortly be getting on to releasing the various large textures that I have in my program (1024*768*32), if I call release on the texture object, will that memory be freed up for me or not? Kind regards. Mark Coleman

Share this post


Link to post
Share on other sites
Quote:
Here's an example... In my program I have a full screen 60mb AVI which I play at the beginning of the application. When this loads up I can see, in Windows Task Manager, that Direct Show is loading approx 15mb of this into memory.

However when I release all the DirectShow interfaces this does not go down again.

Task manager shows the working set of the process. Which is not the amount of memory it's taking - it's the amount of memory windows reserves for the process in physical memory. To quote the documentation of SetProcessWorkingSetSize:
The working set of a process is the set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. The minimum and maximum working set sizes affect the virtual memory paging behavior of a process.


To see how much your process is taking, minimize it. Check this knowledgebase article

Quote:
I was under the impression that if I released all the components DirectShow would free up memory for me... Is this incorrect?

It frees the memory.

Quote:
Also, I will shortly be getting on to releasing the various large textures that I have in my program (1024*768*32), if I call release on the texture object, will that memory be freed up for me or not?

It will be freed.

Share this post


Link to post
Share on other sites
One other question, I read in the Knowledge Base article that I could explicity trim the WorkingSetSize by calling SetWorkingSetSize() with -1 for both the dwMinimumWorkingSetSize, and the dwMaximumWorkingSetSize.

I thought I could execute this at the end of each release method so that the memory usage was always accurate.

Does anybody know of any reason why this might be a bad idea?

Thanks in advance.

Mark Coleman

Share this post


Link to post
Share on other sites
Quote:
Original post by ace_lovegrove
Could always overload new and delete and keep track more accurately.

Risky and tricky though...
And it won't track COM objects.

Quote:
Original post by mrmrcoleman
One other question, I read in the Knowledge Base article that I could explicity trim the WorkingSetSize by calling SetWorkingSetSize() with -1 for both the dwMinimumWorkingSetSize, and the dwMaximumWorkingSetSize.

I thought I could execute this at the end of each release method so that the memory usage was always accurate.

Does anybody know of any reason why this might be a bad idea?
It's pointless for release mode, but may be handy for debugging. If you're doing it for debugging, then I can't see any problem with it.
However, if you have the debug runtimes installed, DirectX will tell you if there's any leaks when your application terminates.

Share this post


Link to post
Share on other sites
Quote:
Original post by mrmrcoleman
One other question, I read in the Knowledge Base article that I could explicity trim the WorkingSetSize by calling SetWorkingSetSize() with -1 for both the dwMinimumWorkingSetSize, and the dwMaximumWorkingSetSize.

I thought I could execute this at the end of each release method so that the memory usage was always accurate.

Does anybody know of any reason why this might be a bad idea?

When you pass -1 for both parameters, you essentially set the working size to 0, i.e. you swap the process out of physical RAM, into virtual memory. This is very bad for performance, because when the instructions following the resource release execute, they'll generate lots of page faults. A page fault happens when a request is made to a logical memory address that does not reside in physical memory. In that case, the OS loads a chunk - called 'page' - of memory from virtual memory into physical memory to service the memory access. Thus, you generate lots of page faults, and end up loading from virtual memory, which is slow.

Generally, you shouldn't be using TaskManager as a memory usage tracker.

Share this post


Link to post
Share on other sites
Yes, I have been playing around all afternoon with this and basically it KILLS performance as Muhammad quite rightly said...

I have switched to perfmon which does a much better job of telling me how much memory my application is eating and the good new is that it isn't all that bad!

Thanks for the input Evil Steve, but I am not doing to to find leaks! It is an exercise to see how much difference it actually makes to have resources paged in and out of memory on worker threads. I am currently trying to balance the memory usage against the responsiveness and it is looking good.

Another question ( or two or three!)... Is there anyway of knowing (or guess - timating) how much of an AVI will be loaded into memory under DirectShow? It seems a bit hit and miss at the moment.

Also, say I have a 1024x768x32 jpg which is say 230k in the file... Am I to assume that it will be 1024x768x32 bytes in memory or are there other factors to consider.

ONE MORE!! ;P

How am I to know whether textures are being put in video memory or being AGP'd from main memory?

Thats all for now!

Thanks for the quick feedback guys, as always it is greatly appriecated.

edit: Actually, one MORE thing!

What do you guys (i.e. Evil Steve, Coder) use to measure memory usage properly?

Mark Coleman

Share this post


Link to post
Share on other sites
Quote:
Original post by mrmrcoleman
Another question ( or two or three!)... Is there anyway of knowing (or guess - timating) how much of an AVI will be loaded into memory under DirectShow? It seems a bit hit and miss at the moment.

Raw AVIs store each frame as a bitmap, which is why their size is so big. I don't know about compressed ones. You'd have better chances on getting this answered in a separate thread. Make sure you put "DirectShow" in the title, because we have a few people familiar with DirectShow here.

Quote:
Also, say I have a 1024x768x32 jpg which is say 230k in the file... Am I to assume that it will be 1024x768x32 bytes in memory or are there other factors to consider.

Assuming you used a 32 bit format, it'll be at least 1024x768x32. Typically it'll be larger, because surface pitch is almost always greater than the actual width. If you're doing mipmaps, you'll see about 1/3 increase in size.

Quote:
How am I to know whether textures are being put in video memory or being AGP'd from main memory?

You can't.

Quote:
What do you guys (i.e. Evil Steve, Coder) use to measure memory usage properly?

On the devices I code for, I use my own memory management layer for memory usage and leak tracking. On the PC, you can make use of Paul Nettle's memory manager. It's good, powerful and free. Don't have the URL at hand, though. [google]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this