区别 SAFE_RELEASE(), SAFE_DELETE()
我是编程新手。
我想知道释放和删除功能。
当我用new分配内存时,我应该用delete终止它。
但是什么时候应该使用释放呢?
释放和删除有什么区别...?
I'm newbie in programming.
I'm wondering release and delete function.
When I allocate memory with new, I should terminate it with delete.
But when I should use release?
What's the difference release and delete...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在寻找定义,您会发现
SAFE_DELETE 应该用于用 new
SAFE_RELEASE 分配的内存,应该为 com 对象(如 directx 对象)调用 SAFE_RELEASE ,并且“幕后”正在执行类似的操作,
它会减少引用计数器并释放对象如果没有更多的参考资料。
If you are looking for definition you will find
SAFE_DELETE should be used for memory allocated with new
SAFE_RELEASE should be called for com objects (like directx objects) and "under the hood" is doind something like this
it decrements a reference counter and releases the object if there are no more references to it.
c++ 没有发布版本,也许您在涉及 COM+ 的教程中看到过?喜欢 DirectX 吗?
当然,
SAFE_RELEASE
和SAFE_DELETE
实际上并不是 C++ 的一部分,很可能是在某些头文件中定义的宏。无论如何,规则如下:
delete[]
你new[]
delete
你new
free ()
你的malloc()
/calloc()
/realloc()
c++ has no release, perhaps you saw that in a tutorial involving COM+? Like DirectX?
Certainly,
SAFE_RELEASE
andSAFE_DELETE
are not actually part of c++ and are likely to be macros defined in some header file.Anyway, here's the rules:
delete[]
what younew[]
delete
what younew
free()
what youmalloc()
/calloc()
/realloc()