I have a singleton class that has mutableDictionary. I initialize the dictionary in my root viewController. later I would like to free the dictionary and free the memory. Although the hold count is 1, the release causes a failure:
- [CFDictionary release]: message sent to the freed instance
Is it possible to release the singleton property?
thank
First I repeat what has been said many times here: Do not call -retainCount!! This is an implementation detail.
-retainCount
See: StackOverflow | when to use saveCount for an excellent recount on why you are not using saveCount.
, . , ( , ) . . , .
, :
, http://bugreport.apple.com , -retainCount . , .
. singleton , .
, Cocoa , , " 1", , - , :
, , .
, , . , 0 - 1, . , , - , 0 - 0 .
. , . , , . singleton, singleton , .
re retainCount. .
retainCount
/
, ,
[dictionary removeAllObjects], ,
[dictionary removeAllObjects]
If the dictionary stores the objects that you want to unlock in the event of a memory warning, perform a one-time observation UIApplicationDidReceiveMemoryWarningNotificationand delete all its objects there.
UIApplicationDidReceiveMemoryWarningNotification
If you really want your implementation to free the entire dictionary, I would override the synthesized getter and add singleton methods to interact with the dictionary as follows:
in MySingleton.m:
- (NSMutableDictionary *)myDictionary { if (!_myDictionary) { _myDictionary = [[NSMutableDictionary alloc] init]; } return _myDictionary; } - (void)setObject:(id)object inMyDictionaryForKey:(NSString *)key { [self.myDictionary setObject:object forKey:key]; } - (void)removeObjectInMyDictionaryForKey:(NSString *)key { [self.myDictionary removeObjectForKey:key]; if ([self.myDictionary count] == 0) { self.myDictionary = nil; } } - (void)removeAllObjectsFromMyDictionary { self.myDictionary = nil; }
Source: https://habr.com/ru/post/1795814/More articles:How to insert distinguishing records from table A to table B (both tables have the same structure) - sqlRequireJS: проблема, включающая jquery easing pack после оптимизации - javascriptPhantom update in Django admin - djangoHow to get all embedded document values using official C # driver for MongoDB? - c #TCP echo server that only drives off the first packet (C language) - cINSERT SQL query does not work, inserting values into my database - sqlThe preferred way to access control text in postback is c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1795817/whats-the-recommended-way-to-report-model-state-and-application-errors-to-client&usg=ALkJrhiOPlhyk0yj-w7G7kHU3ROJ4uujIAjquery $ .ajax several times (one extra after each subsequent submission) - javascriptHow to change response to HTTP OPTIONS request in Spring MVC 2.5 application? - javaAll Articles