c++ - Not deleting dynamically allocated memory and let it get free by the OS after programme termination -
i have read question , answer dynamically allocated memory after program termination, , want know if okay not delete dynamically allocated memory , let freed os after programme termination. so, if have allocated memory objects need thoughout programme, ok skip deleting them @ end of programme, in order make code run faster?
the short answer yes, can, long answer possibly better not that: if code needs refactored , turned library, delivering considerable amount of technical debt person going job, you.
furthermore, if have real, hard-to-find memory leak (not memory leak caused intentionally not freeing long-living objects) it's going quite time consuming debug valgrind due considerable amount of noise , false positives.
have @ std::shared_ptr
, std::unique_ptr
. latter has no overhead.
Comments
Post a Comment