Corona SDK 内存泄漏

发布于 2024-12-06 08:35:47 字数 289 浏览 0 评论 0原文

我正在为游戏设计课程使用 Corona 编写一款游戏,虽然我仍在学习,但我已经掌握了大部分基础知识。现在,我遇到一种情况,程序在播放大约两分钟左右后速度变慢,我不完全确定原因。我已经实现了代码来删除所有已达到其目的的机构,我什至将其设置为在删除每个机构时打印通知。

http://www.mediafire.com/?5fz7ru0c6euwq1k

这是下载链接。非常感谢任何帮助。谢谢!

I'm writing a game using Corona for a game design class and though I'm still learning, I've got most of the basics down. Right now, I have a situation where the program slows down after about two minutes or so of playing, and I'm not entirely sure why. I've already implemented code to remove all bodies which have served their purpose and I even have it set up to print a notification when each one is removed.

http://www.mediafire.com/?5fz7ru0c6euwq1k

This is the download link. Any help is greatly appreciated. Thanks!

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

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

发布评论

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

评论(1

焚却相思 2024-12-13 08:35:47

首先,你检查过内存使用情况吗?如果问题逐渐减慢,这听起来肯定像是内存泄漏,但您需要检查内存使用情况以确定。将内存使用情况打印到控制台,如下所示:

print("mem "..collectgarbage("count"))

将其放入 EnterFrame 侦听器中,以便您可以在应用程序运行时连续观察内存使用情况。

现在,一旦您看到应用程序消耗的内存,任何调试中最关键的步骤就是隔离问题。也就是说,在导致问题的代码中将其清零。对于某些问题,您可以依靠将调试消息打印到控制台等技术,但对于内存泄漏,您最好的选择通常是有选择地注释掉代码部分,以查看其对内存的影响。

例如,先注释掉某个屏幕上的事件监听器,然后检查内存使用情况。如果泄漏消失了,那么您就知道问题与那些事件侦听器有关。如果泄漏不受影响,则恢复这些事件侦听器并注释掉下一个可能的内存泄漏原因。冲洗并重复

一旦您知道导致泄漏的确切代码部分,您可能就能看到需要修复的内容。如果没有,请询​​问该特定代码。

First off, have you checked the memory usage? If the problem gradually slows down that certainly sounds like a memory leak, but you need to check the memory usage to be sure. Print out memory usage to the console like so:

print("mem "..collectgarbage("count"))

Put that in an enterFrame listener so that you can watch the memory usage continuously while your app is running.

Now once you are seeing the memory consumed by your app, the most crucial step in any sort of debugging is isolating the problem. That is, zero in on the spot in the code that causes the problem. For some problems you can rely on techniques like printing debug messages to the console, but for a memory leak your best bet is often to selectively comment out sections of the code to see what affect that has on memory.

For example, first comment out the event listeners on one screen and then check the memory usage. If the leak is gone, then you know the problem was something to do with those event listeners. If the leak is unaffected, then restore those event listeners and comment out the next possible cause of a memory leak. rinse and repeat

Once you know the exact section of code that is causing the leak, you will probably be able to see what you need to fix. If not, ask about that specific code.

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