didReceiveMemoryWarning 麻烦

发布于 2024-11-08 11:56:37 字数 1010 浏览 0 评论 0 原文

我的 didReceiveMemoryWarning 中应该包含什么?我没有看到任何我可以释放的东西仍然留在记忆中。我为我的 managedObjectContext 设置了一个属性,这就是 ivars 的属性。

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *calendar = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"calendar.png"]style:UIBarButtonItemStyleBordered target:self action:@selector(viewCal)];
    self.navigationItem.rightBarButtonItem = calendar;
    [calendar release];

    UIBarButtonItem *settings = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gears.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(viewSettings)];
    self.navigationItem.leftBarButtonItem = settings;
    [settings release];

    [SHK flushOfflineQueue];
    [self clearNullWorkouts];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

What should be in my didReceiveMemoryWarning? I do not see anything I can release that is still in memory. I have a property set up for my managedObjectContext, that's it for ivars.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *calendar = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"calendar.png"]style:UIBarButtonItemStyleBordered target:self action:@selector(viewCal)];
    self.navigationItem.rightBarButtonItem = calendar;
    [calendar release];

    UIBarButtonItem *settings = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gears.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(viewSettings)];
    self.navigationItem.leftBarButtonItem = settings;
    [settings release];

    [SHK flushOfflineQueue];
    [self clearNullWorkouts];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

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

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

发布评论

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

评论(1

浮生面具三千个 2024-11-15 11:56:37

SHK 中的什么内容让您需要清除 OfflineQueue 以及clearNullWorkouts 的作用是什么?这些可能是您在 didReceiveMemoryWarning 期间需要释放的资源。另外,仅仅因为 didReceiveMemoryWarning 触发并不意味着您必须清理任何内容,例如,如果您仍在显示视图、播放正在引用的音频文件等。当调用此函数时,您需要释放未显示的图像、未播放的音频等内容。调用 didReceiveMemoryWarning 后,未显示的视图控制器将调用 viewDidUnload 并在这里,您可以将所有 IBOutlet/编程视图设置为 nil 并释放更多内存。 Apple 在 内存管理编程指南

What is in SHK that makes you flushOfflineQueue and what does clearNullWorkouts do? Those may be the kind of resources that you need to free during didReceiveMemoryWarning. Also just because didReceiveMemoryWarning fires that does not mean you have to clean up anything, for instance if you are still displaying the view, playing an audio file that is being referenced, etc. When this called you need to release things like images that are not being displayed, audio that is not being played, etc. After didReceiveMemoryWarning is called view controllers that are not being displayed will have viewDidUnload called and that is where you will set all IBOutlets/programmatic views to nil and release more memory. Apple discusses this in the Memory Management Programming Guide.

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