从向量取消分配堆内存. [英] Deallocating heap memory from a vector.

查看:58
本文介绍了从向量取消分配堆内存.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个向量,其中存储了结构对象.现在我需要释放内存.
请告诉我如何?

I have a vector in which I stored objects of structures. Now I need to deallocate the memory .
Kindly tell me how?

推荐答案

使用 ^ ]方法.


内存将由矢量析构函数释放(除非您在矢量中存储了指针).
如果向量仅包含指向对象的指针(因为您告诉我们对象是堆分配的),则必须delete每个指针(对向量项进行循环).
Memory will be released by vector destructor (unless you have stored pointers inside the vector).
If your vector contains just pointers to the objects (since your are telling us the objects are heap allocated) then you have to delete every pointer (make a loop on vector items).


这篇关于从向量取消分配堆内存.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆