release vs setting-to-nil to free memory
Posted
by Dan Ray
on Stack Overflow
See other posts from Stack Overflow
or by Dan Ray
Published on 2010-06-02T18:12:09Z
Indexed on
2010/06/02
18:13 UTC
Read the original article
Hit count: 266
In my root view controller, in my didReceiveMemoryWarning method, I go through a couple data structures (which I keep in a global singleton called DataManager), and ditch the heaviest things I've got--one or maybe two images associated with possibly twenty or thirty or more data records.
Right now I'm going through and setting those to nil. I'm also setting myself a boolean flag so that various view controllers that need this data can easily know to reload. Thusly:
DataManager *data = [DataManager sharedDataManager];
for (Event *event in data.eventList) {
event.image = nil;
event.thumbnail = nil;
}
for (WondrMark *mark in data.wondrMarks) {
mark.image = nil;
}
[DataManager sharedDataManager].cleanedMemory = YES;
Today I'm thinking, though... and I'm not actually sure all that allocated memory is really being freed when I do that. Should I instead release
those images and maybe hit them with a new alloc
and init
when I need them again later?
© Stack Overflow or respective owner