PotatoOfDoom / CyberFSR2

FidelityFx Super Resolution 2.0 for Cyberpunk
MIT License
620 stars 67 forks source link

Mem leaks? #23

Closed patrolez closed 2 years ago

patrolez commented 2 years ago

Hello, I can see some C++ STL misconception in usage in the code.

https://github.com/PotatoOfDoom/CyberFSR2/blob/main/CyberFSR/CyberFsr.cpp#L29

Objects created dynamically by the new keyword while being referenced (stored) as pointers in STL containers (e.g. std::map, std::unordered_map, std::vector) are not being itself a subject of clearing/erasing done by the container (their destructor would not be triggered).

In this case you need to chose among:

  1. to call explicitly delete on such pointer to delete the object, then remove the pointer entry from the container,
  2. to use some smart pointer from the standard library unique_ptr/shared_ptr,
  3. just store whole objects in an STL container (but not just pointers) and get familiar with reference (address) invalidation cases for this specific STL container - https://stackoverflow.com/questions/6438086/iterator-invalidation-rules-for-c-containers,
  4. write own RAII variation of a smart pointer which would denote that a lifetime of the object is being managed by the container intentionally.

An STL container of pointer will NOT clean up the data pointed at

https://stackoverflow.com/a/383084/12755962

PotatoOfDoom commented 2 years ago

thanks for the heads-up. I'll fix it asap.