对象释放速度不够快,导致应用程序重新启动崩溃

发布于 2024-12-05 12:36:29 字数 405 浏览 1 评论 0原文

我有一个应用程序,其中有 5 组动画,我将它们存储在数组中。触摸按钮后,动画会随机播放。这一切都很完美,但是当我退出应用程序并立即重新打开时,我注意到一个错误,我会看到我的主视图,然后它会跳转到其中有动画的第二个视图。 (这种情况不应该发生,因为你必须点击主视图才能使其在第二个视图中模态交换。如果我与它交互,一切都会工作几秒钟,然后它就会关闭,没有崩溃日志。

我终于意识到有些对象的释放速度一定不够快,因为如果我关闭应用程序并等待三秒钟,然后重新打开,一切都会正常执行,

我不想放下代码来显示,因为这更像是一个头脑风暴问题。我希望任何可以为我指明正确方向的见解我更改了很多代码以摆脱便利方法,并在我的 dealloc 中定义并释放所有变量,

有没有办法真正告诉应用程序在退出时杀死所有内容?背景所以这有点奇怪谢谢你的帮助我对这个和学习还是陌生的!

I have an app where I have 5 sets of animations that I'm storing in an array. The animations get picked to play randomly after a button touch. This is all working perfectly, however I noticed a bug when I quit the app and reopen immediately, I'll see my main view, then it'll jump to my second view that has the animation in it. (This shouldn't happen since you have to tap the main view in order for it to modally swap in the second view. If I interact with it everything works for a few seconds, then it closes with no crash log.

I finally realized that some of the objects must not be getting released fast enough, since if I close the app and wait three seconds, then reopen, everything executes fine.

I didn't want to put down code to show as this is more of a brainstorming question. I'd love any insight that could point me the right way. I changed a lot of my code to get rid of convenience methods and have all my variables defined and then released in my dealloc.

Is there a way to truly tell the app to kill everything on quit? It's not set to run in the background so this is a bit odd. Thanks for your help I'm still new to this and learning!

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

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

发布评论

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

评论(3

血之狂魔 2024-12-12 12:36:30

好吧,在整个周末都在研究这个问题并进行了更多研究,将我的应用程序的准系统版本与我的预发布版本进行比较后,我将内存泄漏追溯到我正在使用的 Flurry Analytics api。显然我遇到了与这里的帖子相同的问题:使用最新的 Flurry SDK 和 ios4 重新启动时应用程序挂起。我通过将这些可选方法设置为 false 解决了这个问题,因为它们在应用程序终止后需要额外的时间来发送数据,并且根据连接情况,需要几秒钟的时间。

FlurryAnalytics.h

/*
 optional session settings that can be changed after start session
 */
+ (void)setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose;    // default is YES
+ (void)setSessionReportsOnPauseEnabled:(BOOL)setSessionReportsOnPauseEnabled;  // default is YES

希望这对经历过与我类似的事情的其他人有所帮助!

Alright, after working on this all weekend and doing more research comparing a barebones version of my app to my prerelease version, I traced memory leaks to the Flurry Analytics api that I am using. Apparently I was suffering from the same issue as the post here: App hangs on restart with latest Flurry SDK and ios4 . I resolved this by setting these optional methods to false, since they take extra time to send data after the app terminates, and depending on the connection it takes a few seconds.

FlurryAnalytics.h

/*
 optional session settings that can be changed after start session
 */
+ (void)setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose;    // default is YES
+ (void)setSessionReportsOnPauseEnabled:(BOOL)setSessionReportsOnPauseEnabled;  // default is YES

Hope this helps anyone else who experienced something similar to me!

楠木可依 2024-12-12 12:36:30

所有应用程序都可以默认进入后台。通常它们不会在那里做任何事情,但它们会以冻结状态停留在那里,当您再次打开它们时,您的程序不会重新启动,它只是从中断处继续。

任何设置为动画委托的内容都可能不会被释放,因为它会为此目的而保留,直到动画完成。

您可以向应用程序委托添加一个 applicationDidEnterBackground: 方法,以便在您的应用程序进入后台时收到通知,但具体需要执行的操作取决于应用程序的设计。您还可以添加 applicationWillEnterForeground: 来执行重新启动时需要执行的任何操作,而不是重新启动。

您可以通过启动一个持续时间为 0.0 的新动画来强制动画完成(如果由于某种原因您不能这样做,则可以非常短)。

All apps can enter the background by default. Normally they do not do anything there, but they stay there in a frozen state and when you open them again, your program does not restart, it just picks up where it left off.

Anything that's set as an animation delegate might not get released, since it's retained for that purpose until the animation completes.

You can add an applicationDidEnterBackground: method to your app delegate to get informed when your app is going into the background, but exactly what you need to do depends on the design of your app. You can also add applicationWillEnterForeground: to do anything you need to do differently when restarting, as opposed to newly starting.

You might be able to force your animations to complete by starting a new animation with duration 0.0 (or very short if for some reason you can't do that).

野心澎湃 2024-12-12 12:36:30

如果仅当您的应用程序转到 bkgnd 并返回时才会发生这种情况,并且您不介意应用程序每次返回时都重新启动,那么只需将 UIApplicationExitsOnSuspend 放入您的应用程序的 plist 即可。在我所有的情况下,当应用程序进出 bkgnd 并从 bkgnd 返回时,会发生这些和其他不好的事情,这很有帮助。

虽然双击时您可能仍会在按钮上看到该应用程序,但它实际上已停止并将重新启动。我了解到,显示在按钮上的应用程序并不总是必须运行或存储在 bkgnd 中。

附注不要忘记将 UIApplicationExitsOnSuspend 的值设置为 YES

If this happens only if your app goes to bkgnd and comes back AND you don't mind if the app restarts everytime it comes back then just put UIApplicationExitsOnSuspend in your app's plist. In all my cases where these and other bad things happen with apps going to and returning from bkgnd this helped.

While you might still see the app on the buttom when double tapping it is really stopped and will restart. Apps that show on the buttom do not always have to run or be stored in the bkgnd I learned.

ps. don't forget to set the value of UIApplicationExitsOnSuspend to YES

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