Symbian C++ 的内存管理实践和工具

发布于 2024-07-09 21:25:32 字数 338 浏览 9 评论 0原文

我已经基本完成了我的第一个 Symbian 应用程序,但是在我匆忙的学习中很少关注内存管理以及推送和清理堆栈?

有人可以指出我在这里使用的一些最佳实践的方向,也许还有一些最好的泄漏检测/内存分析工具。

例如,如果我在函数内获取 TDesC 或 TPtrC16,那么我该如何以最好的方式清理它们,是否只是

TPtrC16 temp = ...
temp.CleanupClosePushL();
CleanupStack::PopAndDestroy()

......对于所有内容?

谢谢,请原谅我,我自认是 Symbian n00b。

I have pretty much finished my first working Symbian application, but in my hastened learning have paid little attention to memory management and pushing to and cleaning up the stack?

Could somebody please point me in the direction of some of the best practises to use here, and maybe some of the best leak detection/memory profiling tools.

For example, if I grab a TDesC or a TPtrC16 inside a function, how do I then clean them up the best way, is it simply

TPtrC16 temp = ...
temp.CleanupClosePushL();
CleanupStack::PopAndDestroy()

..for everything?

Thanks and please forgive me, I am a self confessed Symbian n00b.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人骨 2024-07-16 21:25:32

我过去曾使用 Symbian 的 HookLogger 来跟踪和调查内存泄漏。 它不是最好的,但确实有帮助。 此外,每当您退出应用程序时,如果发生内存泄漏,堆标记都会引发 ALLOC 恐慌。 这些恐慌提供的信息几乎没有帮助,但它很好地表明某处存在内存泄漏。 从那里,您可以使用 HookLogger 等工具来缩小泄漏发生在代码的哪一部分。

我在回复此帖子时提到了一些 Symbian 资源。 虽然所有这些对我来说都是最有用的,但我确实找到了这本书 经过认证的 Symbian 开发人员入门 非常有帮助。 如果你能得到它,我绝对会推荐它。 读起来很快,但它很好地解释了这些概念,包括有关内存管理和描述符的内容。

I have in the past used HookLogger from Symbian to trace and investigate memory leaks. It is not the best, but it sure does help. Also, the heap markers raise ALLOC panics in case of memory leaks whenever your exit your application. The information those panics provide is barely helpful, but it is good indication that there is a memory leak somewhere. From there, you may use tools like HookLogger to narrow in on which part of the code the leak is getting introduced at.

I mentioned a few Symbian resources in reply to this thread. While all those have been most useful for me, I did find the book Accredited Symbian Developer Primer immensely helpful. If you could get your hands on it, I would definitely recommend it. It is a quick read, but it explains the concepts brilliantly, including things about memory management and descriptors.

尐籹人 2024-07-16 21:25:32

存储在堆栈上的东西不需要存储在清理堆栈上(除非它们需要特殊处理(R类等,见下文))

清理堆栈用于在发生离开(认为异常)时删除对象,否则会泄漏记忆。

清理堆栈的实际使用是通过静态函数 CleanupStack::PushL(..) 和 CleanupStack::Pop / PopAndDestroy。

某些类(例如 RFile、RF)必须关闭而不是删除,因此对于这些函数,调用了它们的 ::Close 函数,因此您应该使用全局函数 CleanupClosePushL(),而不是在离开时调用对象上的删除运算符,它调用类的 ::Close 函数。

要检查代码是否存在内存泄漏,可以使用宏 __UHEAP_MARK; 和 __UHEAP_MARKEND; 这将验证这两个调用之间堆上没有留下任何内容。

如果您在 CActive 的::RunL 的清理堆栈上留下任何内容,则活动调度程序将出现紧急情况。

作为一般技术,如果您调用的函数可以离开(由尾随“L”表示),则必须将任何必须删除或关闭(等)的内容添加到清理堆栈中。

Things stored on the stack do not need to be stored on the cleanup stack (unless they need special handling (R Classes etc, see below) )

The cleanup stack is for deleting objects when a leave (think exception) occurs, which would otherwise leak memory.

The actual use of the cleanup stack is through the static functions CleanupStack::PushL(..) and CleanupStack::Pop / PopAndDestroy.

Some classes such as RFile,RFs have to closed rather than deleted, so for these functions have their ::Close function called so you should use the global function CleanupClosePushL(), which instead of calling the delete operator on your object on a leave, it calls the class' ::Close function instead.

To check your code for memory leaks, you can use the macros __UHEAP_MARK; and __UHEAP_MARKEND; which will verify that nothing is left on the heap from between these two calls.

If you leave anything on the cleanupstack in an CActive's::RunL, the active scheduler will panic.

As a general technique, if a function that you are calling could leave, (denoted by a trailing 'L') then anythign that must be deleted or closed (etc) should be added to the cleanup stack.

一生独一 2024-07-16 21:25:32

它需要不到 10 页的篇幅来正确解释您需要了解的有关 Symbian C++ 的 CleanupStack 和内存管理的所有信息。

无耻插件:这本书是专门为你的 n00bness 级别编写的:
http://www.quickrecipesonsymbianos.com

It takes a little under 10 pages to properly exmplain all you need to know about the CleanupStack and Memory management for Symbian C++.

Shameless plug : this book was written specifically for your level of n00bness:
http://www.quickrecipesonsymbianos.com

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文