Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / make image from memblock + texture object --->memory leak

Author
Message
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 4th Sep 2013 10:32
Hi,
see code: if we increase the size of the bitmap (line 17), the memory leak is also increasing. If you remark the line 36, the leak stops, but the object is not properly textured.



DirectX 9.0c (February 2010)/ DBClassic v1.20
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Sep 2013 20:21
Try adding a SYNC after deleting the image. Without the sync it's likely that just the reference to the pointer is removed but the memory (DD surface) is not released. Since you recreate the image immediately after deleting it, it's likely that the same memory area is being used or overlapped without the old memory being released so there is residual garbage.

Another thing to try is to use two image numbers and swap them so that either is used at a time allowing the SYNC at the end of the loop to handle the cleanup:




I'm not at a computer to test this but I remember doing experiments a while ago.

At one point, it was encouraged to texture an object and then delete the image to save memory. However, I remember running tests on this and the memory and the textures eventually get screwed up.

Three things that I take as law in general:

Sync after Get Image - before using image
Sync after Delete image - before reassigning image
Delete Sprite BEFORE Deleting image

Enjoy your day.
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 6th Sep 2013 11:35
I have already tried everything you suggested, but the memory leak is still present.
I replaced the cube by a sprite, it does not leak!
At this point, I'm sure the bug comes from 'texture object', and I think that the problem is internal and can not be solved.

DirectX 9.0c (February 2010)/ DBClassic v1.20
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Sep 2013 22:10 Edited at: 7th Sep 2013 22:12
Hi Silverman,

I had a chance to run your original code I do see a memory leak in video ram when I test system dmem available().

Also note that GET IMAGE 0,0,31,31 only grabs 31X31 pixels so your memblock calculations may be off.

I did some tests and it doesn't seem to be the texturing of the object, but I do think it could be indirectly related.

The leak seems to be from the image being converted from either system memory to video memory or from raw data to a direct draw surface.

There is no leak in making the image from a memblock - but there is a leak when the image data is deleted and the same image reused. So you've opened my eyes to some potential problems with what I thought was working in the past.

I have a solution for your code. We make a bitmap out of the memblock and capture that as an image. This both updates the image and avoids the memory leak. I've made slight adjustments to your code:



Enjoy your day.
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 8th Sep 2013 12:23 Edited at: 8th Sep 2013 12:24
Thank Latch.I reaches the same code as you. I noticed a couple 'delete image / make image from memblock' and 'make bitmap from memblock / get image' are about the same speed, but longer than one'make image from memblock'.

DirectX 9.0c (February 2010)/ DBClassic v1.20

Login to post a reply

Server time is: 2020-08-12 02:59:22
Your offset time is: 2020-08-12 02:59:22