0
votes

I'm using C++ Builder XE7. Whenever a form resizes I need to rebuild a D2D bitmap, which I create with CreateBitmap(). As this will quickly eat up all video memory, I want to destroy the previous bitmap before creating a new one. Oddly enough I cannot find any information how to destroy this _di_ID2D1Bitmap. I tried the Release() method but that just gives me an AV in line 291 of systobj.h.

What is the proper way to destroy a _di_ID2D1Bitmap?

Thanks.

1
If _di_ID2D1Bitmap is the ID2D1Bitmap interface, just remove all references to it (eg. mySavedBMPRef = null).Peter Kostov
Thanks @PeterKostov. Is it that simple? My confusion comes from the fact I look at this like a pointer, which I now understand it isn't. I assume not nilling it but replacing it to "point" to the new bitmap works just as well?Mike Versteeg
_di_ID2D1Bitmap is a DelphiInterface. A variable of that type is a pointer. You don't have to free it manually, because there is an automatic reference counting - ie - when there are no references left, it will be freed automatically. In short, if you have a pointer P holding just one reference to your ID2D1Bitmap, when you pass it to the CreateBitmap() it will acquire a ref to the new bitmap while the old one will became with 0 references and will be freed.Peter Kostov
Cool, thanks. Not familiar with Delphi so did not know that (nor is it documented). If you post that as answer I'll give you proper credits.Mike Versteeg

1 Answers

2
votes

_di_ID2D1Bitmap is a DelphiInterface. An interface reference in Delphi is a pointer to pointer to an IMT. So, a variable of _di_ID2D1Bitmap type is a pointer.

You don't have to free it manually, because there is an automatic reference counting - ie - when there are no references left, it will be freed automatically. You may check the IInterface._AddRef and IInterface._Release methods.

In short, if you have a pointer P holding just one reference to your ID2D1Bitmap (ie _di_ID2D1Bitmap), when you pass it to the CreateBitmap() it will acquire a ref to the new bitmap while the old one will became with 0 references and will be freed.

Here are some useful reads: