w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Do I need to explicitly free the memory in managed C++?
For each:
  • new[] - delete[] should be called
  • new - delete should be called
  • malloc() - free() should be called
  • ref new / gcnew - a memory is deallocated automatically
You should avoid taking care of memory management on your own as much as possible by:
  • following RAII idiom
  • prefering objects with automatic storage duration over dynamically allocated ones
  • taking advantage of smart pointers that will ensure that the memory is freed using the appropriate (explicitly specified) means and it will happen so on every return / exit path (even when an exception is thrown)
  • etc.

In this case you used new[] for allocation, so you should deallocate this memory by calling:

delete[] mBytes;




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.