简体   繁体   中英

How to get Process ID and use EmptyWorkingSet on Windows?

I use a game engine, as the game goes on, any unused textures, like from past levels, seem not to be cleared automatically. The developers though state that DirectX does not need to clear its textures manually, it simply swaps them out automatically when not used.

However my game seems to increase its memory usage with each different level. I am still testing for leaks and whatnot, however I'd like to use EmptyWorkingSet winapi function to lower the memory usage.

I do have the HWND of the application, how can I get its proccess id and use EmptyWorkingSet to clear the unused memory?

Do NOT do this.

EmptyWorkingSet() is not a magic bullet and it will only cause the memory used by your App to appear lower when queried by Task Manager, however the memory will only have been paged to disk and you'll be getting lots of page faults as a result. (A lose-lose situation)

The only correct way to fix this is to fix your memory leaks. Use valgrind and cachegrind to locate the issue, and make sure you're releasing your memory in all the places it needs to be released.

Also if the memory usage you see going up is Physical Memory in Task Manager, this is not DirectX, as Direct3D will store all texture information in server memory (ie: VRAM)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM