Reputation: 51
Sorry for my english. I want to free memory that was used by gcroot objejct. Here is a simple example that returns me an error. On MSDN I found that there is a Dispose() method for Bitmap object. When I'm trying to use this method for gcroot object MS VC 2010 returns me this message. How can I free this memory?
picture_box_main_handler.cpp(194): error C2039: Dispose: is not a member of "gcroot"
gcroot<Bitmap^> new_image = gcnew Bitmap(500,500);
new_image.Dispose();
Upvotes: 1
Views: 475
Reputation: 17474
You aren't trying to call the method on the 'gcroot' itself (so you don't want the . syntax).
However, Dispose
for IDisposable
is special in C++/cli. You use the delete
keyword for that:
So you can just call:
delete new_image;
and that will call Dispose on the underlying Bitmap ^
.
You may want to use auto_handle
to take care of disposal automatically. See this question:
C++/CLI Resource Management Confusion
Upvotes: 2