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?
我已经完成了我的第一个Symbian应用程序,但在我的加速学习中很少关注内存管理并推动和清理堆栈?
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
例如,如果我在函数内部获取TDesC或TPtrC16,我该如何以最佳方式清理它们,它是否只是
TPtrC16 temp = ...
temp.CleanupClosePushL();
CleanupStack::PopAndDestroy()
..for everything?
Thanks and please forgive me, I am a self confessed Symbian n00b.
谢谢,请原谅我,我是一个自认为Symbian n00b。
3 个解决方案
#1
3
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.
我过去使用过来自Symbian的HookLogger来跟踪和调查内存泄漏。它不是最好的,但确实有帮助。此外,每当退出应用程序时,堆标记会在内存泄漏的情况下引发ALLOC恐慌。这些恐慌提供的信息几乎没有帮助,但它很好地表明某处存在内存泄漏。从那里,您可以使用像HookLogger这样的工具来缩小泄漏所引入的代码部分。
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.
我在回复这个帖子时提到了一些Symbian资源。虽然所有这些对我来说都是最有用的,但我确实发现“Accredited Symbian Developer Primer”这本书非常有用。如果你可以得到它,我肯定会推荐它。这是一个快速阅读,但它精辟地解释了概念,包括有关内存管理和描述符的内容。
#2
2
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) )
存储在堆栈中的东西不需要存储在清理堆栈中(除非它们需要特殊处理(R类等,见下文))
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.
清理栈的实际用途是通过静态函数CleanupStack :: PushL(..)和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.
一些类,如RFile,RF必须关闭而不是删除,所以对于这些函数调用它们的:: Close函数,所以你应该使用全局函数CleanupClosePushL(),而不是在休假时调用你对象上的delete操作符,它调用类':: Close函数。
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.
要检查代码是否存在内存泄漏,可以使用宏__UHEAP_MARK;和__UHEAP_MARKEND;这将验证这两个调用之间堆上没有任何东西。
If you leave anything on the cleanupstack in an CActive's::RunL, the active scheduler will panic.
如果您在CActive的:: RunL中的cleanupstack上留下任何内容,则活动调度程序将发生混乱。
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.
作为一种通用技术,如果您正在调用的函数可以离开(用尾随的'L'表示),那么必须删除或关闭的任何符号(等)应该添加到清理堆栈中。
#3
1
It takes a little under 10 pages to properly exmplain all you need to know about the CleanupStack and Memory management for Symbian C++.
需要不到10页才能正确地解释所有你需要了解的关于Symbian C ++的CleanupStack和内存管理的知识。
Shameless plug : this book was written specifically for your level of n00bness: http://www.quickrecipesonsymbianos.com
无耻的插件:这本书是专门为你的n00bness级别编写的:http://www.quickrecipesonsymbianos.com
#1
3
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.
我过去使用过来自Symbian的HookLogger来跟踪和调查内存泄漏。它不是最好的,但确实有帮助。此外,每当退出应用程序时,堆标记会在内存泄漏的情况下引发ALLOC恐慌。这些恐慌提供的信息几乎没有帮助,但它很好地表明某处存在内存泄漏。从那里,您可以使用像HookLogger这样的工具来缩小泄漏所引入的代码部分。
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.
我在回复这个帖子时提到了一些Symbian资源。虽然所有这些对我来说都是最有用的,但我确实发现“Accredited Symbian Developer Primer”这本书非常有用。如果你可以得到它,我肯定会推荐它。这是一个快速阅读,但它精辟地解释了概念,包括有关内存管理和描述符的内容。
#2
2
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) )
存储在堆栈中的东西不需要存储在清理堆栈中(除非它们需要特殊处理(R类等,见下文))
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.
清理栈的实际用途是通过静态函数CleanupStack :: PushL(..)和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.
一些类,如RFile,RF必须关闭而不是删除,所以对于这些函数调用它们的:: Close函数,所以你应该使用全局函数CleanupClosePushL(),而不是在休假时调用你对象上的delete操作符,它调用类':: Close函数。
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.
要检查代码是否存在内存泄漏,可以使用宏__UHEAP_MARK;和__UHEAP_MARKEND;这将验证这两个调用之间堆上没有任何东西。
If you leave anything on the cleanupstack in an CActive's::RunL, the active scheduler will panic.
如果您在CActive的:: RunL中的cleanupstack上留下任何内容,则活动调度程序将发生混乱。
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.
作为一种通用技术,如果您正在调用的函数可以离开(用尾随的'L'表示),那么必须删除或关闭的任何符号(等)应该添加到清理堆栈中。
#3
1
It takes a little under 10 pages to properly exmplain all you need to know about the CleanupStack and Memory management for Symbian C++.
需要不到10页才能正确地解释所有你需要了解的关于Symbian C ++的CleanupStack和内存管理的知识。
Shameless plug : this book was written specifically for your level of n00bness: http://www.quickrecipesonsymbianos.com
无耻的插件:这本书是专门为你的n00bness级别编写的:http://www.quickrecipesonsymbianos.com