justinstenning / Direct3DHook

DirectX Capture and Overlays by using Direct3D API hooks
http://spazzarama.com/2011/03/14/c-screen-capture-and-overlays-for-direct3d-9-10-and-11-using-api-hooks
MIT License
582 stars 176 forks source link

Memory leak after unreasonable ammount of DrawOverlayInGame calls and large ImageElement #81

Closed MarcellVokk closed 1 year ago

MarcellVokk commented 1 year ago

Hi!

I've been using this library for a couple of days now, and I came across what I think is a realy small memory leak somewhere... After calling the DrawOverlayInGame method for more than 70,000 times, a memory leak occurs, and becomes more noticable with each redraw...

At 50,000 redraws the memory usage of the target app is 205.4MB, but at 100,000 redraws, it jumps up to 555.1MB, and after that, it goes out of hand, and at 110,000 redraws the memory usage jumps to 1,2GB... The overlay contains 1 image element, which is being changed every frame, and the size of it is 1920x1080...

I'd realy appreciate if someone could look into this, this is a realy cool library!

Thanks, M

Lakritzator commented 1 year ago

I'd advice you to read this issue: https://github.com/justinstenning/Direct3DHook/issues/80 @justinstenning just fixed a memory leak, and you should also make sure your code is working correctly.

justinstenning commented 1 year ago

@Vadkarika2 When you say redraw, do you mean sending a complete new overlay to the target?

Can you please provide a quick and simple reproducible snippet for the scenario?

jazzup commented 1 year ago

In my heavily modified version of this project, I wrap the code in DXSprite.cs -> BeginBatch(ShaderResourceView texSRV) with a using statement:

using (Texture2D tex = _batchTexSRV.ResourceAs<Texture2D>()) { Texture2DDescription texDesc = tex.Description; _texWidth = texDesc.Width; _texHeight = texDesc.Height; } _spriteList.Clear();

It eliminated one of a few leaks I encountered. My overlay changes each time I send it, and @justinstenning , I think this is what @Vadkarika2 is doing.

MarcellVokk commented 1 year ago

Hi! Thanks for the help!

What I mean by redraw is I send a new overlay, yes...

I'll try out what @jazzup suggested, and post an update on the results!

Thanks again, M

MarcellVokk commented 1 year ago

Yep! This fixes my issue, thanks for the suggestion!

MarcellVokk commented 1 year ago

I made a pull request (#82) where I fixed this memory leak using @jazzup's suggestion!

justinstenning commented 1 year ago

Merged, thx