aconstlink / natus

[Discontinued] Software Framework for Audio/Visual/Interactive Real-Time Applications
https://aconstlink.de
MIT License
0 stars 0 forks source link

Memory Leaks all over the Place #333

Closed aconstlink closed 1 year ago

aconstlink commented 1 year ago

Although natus uses smart pointers, there are many dangling sptrs all over the place. The release code of all engine components need to be reviewed and fixed so that all allocated memory is freed at the end of the application.

aconstlink commented 1 year ago

Little comment which might be important. If res<T> objects are not moved but constructed/initialized along with member variable declaration, a reference will get lost, so the memory will not be cleaned up.

Like so:

class my_app
{
  natus::graphics::geometry_object_res_t _geo_obj = natus::graphics::geometry_object_t() ;
  natus::graphics::image_object_res_t _img_obj = natus::graphics::image_object_t() ;

 ... 
  my_app( my_app && rhv )
  {
    _geo_obj = std::move( rhv._geo_obj ) ;
    // if _img_obj is not moved here, a reference will get lost and 
   // the memory will not be released.
  }
}

Yet another solution would be to just do not initialize the variable in the first place and leave initialization to another place:

// from this
natus::graphics::image_object_res_t _img_obj = natus::graphics::image_object_t() ;
// to this
natus::graphics::image_object_res_t _img_obj  ;
aconstlink commented 1 year ago

This should be done. Memory manager does not show any left over allocations for all test applications.