no decrease in memory usage after JSON::Value object goes out of scope #1542
-
Does anyone know an answer to this issue mentioned in StackOverflow? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
got this reply from github copilot: Code:
Q: A: Stack Memory (int z[1024*1024];): The memory allocated for the array z on the stack is indeed released when qq() exits. However, this type of memory release does not necessarily result in an immediate decrease in VmRSS as seen by the operating system. The stack space is reclaimed, but the process's memory footprint as reported by VmRSS might not shrink due to how the OS manages memory. The stack for a thread might not shrink immediately or might be reused for the same thread. Heap Memory (std::unique_ptrJson::Value root): The memory allocated on the heap for root is managed by a std::unique_ptr, which automatically releases the memory when root goes out of scope (which happens when qq() exits). However, similar to stack memory, the release of heap memory back to the operating system might not immediately reflect a decrease in VmRSS. The C++ runtime might keep the memory allocated for future allocations (to avoid the cost of frequent allocations and deallocations). Memory Fragmentation and Management: Memory fragmentation and the memory management strategies employed by both the C++ runtime and the operating system can affect how and when memory is returned to the system. The runtime might hold onto memory for future allocations within the process. Operating System Caching and Memory Management: The operating system might not immediately reclaim or show a reduction in VmRSS because it could be caching memory pages or using them for other purposes within the same process. The OS has complex algorithms for managing memory that do not always immediately reflect changes in a process's memory usage. File Streams and Other Resources: Opening file streams and other resources (like in std::ifstream ifs(path);) allocate memory that is not directly visible as heap or stack memory. These resources are properly closed and cleaned up in your code, but their memory footprint might also affect VmRSS in ways that are not immediately apparent. In summary, the lack of a visible decrease in VmRSS after exiting qq() is likely due to the underlying complexities of memory management at both the runtime and operating system levels. It's important to note that VmRSS is a coarse metric and might not reflect changes in memory usage immediately or in small increments. |
Beta Was this translation helpful? Give feedback.
got this reply from github copilot:
Code:
Q:
i do not see any decrease in VmRSS after exiting from qq()
A:
The behavior you're observing wi…