MAP and Vector clear is not releasing memory

Hi, map and vector stored in shared memory using boost apis and called clear to release memory. when i insert same key i see old data present. want to check using boost map.clear or vec.clear is not removing content. Example: pod_list[] (vector contains following 3 members) pod_info { pod_id du_map. cell_map. } Step 1: Added elements Step 2: pod_list.clear(); Step 3: observed no elements in pod_list empty Step 4: Added only key pod_info.pod_id = 1; pod_list.insert(pod_info); Step 5: i see old content map to this pod_id. after this expecting du_map.size and cell_map size is empty. but du_map,cell_map content is same as before clear want to check is clear will not remove memory? is any other best way to clean this vector. -- Regards, Murali Kishore

On Feb 25, 2025, at 10:33 PM, Murali Kishore via Boost
Hi,
map and vector stored in shared memory using boost apis and called clear to release memory. when i insert same key i see old data present. want to check using boost map.clear or vec.clear is not removing content.
Example:
pod_list[] (vector contains following 3 members) pod_info {
pod_id du_map. cell_map.
}
Step 1: Added elements
Step 2: pod_list.clear();
Step 3: observed no elements in pod_list empty
Step 4: Added only key
pod_info.pod_id = 1;
pod_list.insert(pod_info);
Step 5: i see old content map to this pod_id. after this expecting du_map.size and cell_map size is empty. but du_map,cell_map content is same as before clear
want to check is clear will not remove memory? is any other best way to clean this vector.
vector::clear() does not free memory allocated by the vector to store objects; it calls destructors for the objects it holds. See this stack overflow post (from 2012) https://stackoverflow.com/questions/10464992/c-delete-vector-objects-free-me... — Marshall

Thanks, I'll check it out.
On Wed, Feb 26, 2025 at 8:05 PM Marshall Clow
On Feb 25, 2025, at 10:33 PM, Murali Kishore via Boost < boost@lists.boost.org> wrote:
Hi,
map and vector stored in shared memory using boost apis and called clear
to
release memory. when i insert same key i see old data present. want to check using boost map.clear or vec.clear is not removing content.
Example:
pod_list[] (vector contains following 3 members) pod_info {
pod_id du_map. cell_map.
}
Step 1: Added elements
Step 2: pod_list.clear();
Step 3: observed no elements in pod_list empty
Step 4: Added only key
pod_info.pod_id = 1;
pod_list.insert(pod_info);
Step 5: i see old content map to this pod_id. after this expecting du_map.size and cell_map size is empty. but du_map,cell_map content is same as before clear
want to check is clear will not remove memory? is any other best way to clean this vector.
vector::clear() does not free memory allocated by the vector to store objects; it calls destructors for the objects it holds.
See this stack overflow post (from 2012)
https://stackoverflow.com/questions/10464992/c-delete-vector-objects-free-me...
— Marshall
-- Regards, Murali Kishore
participants (2)
-
Marshall Clow
-
Murali Kishore