It’s true, but i don’t have a local variable. My NSMutableArray is an instance variable, like:

--------------------------------------—
@interface AppDelegate ()
{
NSMutableArray *mymutarr;
}
@end

@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
self->mymutarr = [[NSMutableArray alloc] init];
for (int i = 0; i < 150000; i++) {
[self->mymutarr addObject:@{@“test”:@“a very long string”}]; // Here i have a NSDictionary with 10 keys and values (in this example i wrote only one)
}
[self->nsmutarr removeAllObjects];
self->nsmutarr = nil;

NSLog(@“%i”, [mymutarr count]); // This will be 0, but is not deallocated from the memory
}
@end
----------------------------------------

On 07 Mar 2017, at 22:12, Brian S <fblistserve@...> wrote:


On Mar 7, 2017, at 12:33 PM, Eugen Rosu <eugen.rosu@...> wrote:

Thanks for quick response.
It’s an issue that bother me for a while. I’ll keep searching for a solution.


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    
    // array to hold strings - is autoreleased.
    NSMutableArray *mymutarr  = [NSMutableArray arrayWithCapacity:0];
    
     // load array with string + number
    for (int i = 0; i < 10; i++) {
        [mymutarr addObject:[NSString stringWithFormat:@"%@%d",@"string",i]];
    }
    
    // show array contents
    for ( NSString *eachString in mymutarr) {
        NSLog(@"%@", eachString );
    }
}
@end

Here is the output:

string0
string1
string2
string3
string4
string5
string6
string7
string8
string9



But, the memory value isn’t changing after removing all object from the array.
Even when memory is allocated/inited and then released, it is only eligible for purging. The OS decides exactly WHEN it needs to be purged.

Yes. That i read in Apple docs, but i want to deallocate myself, because that variable is useless after removeAllObjects, but still in memory.


108.4 MB after [mymutarr removeAllObjects] and even mymutarr = nil;
Still stored, but i don’t know why.





self->mymutarr =  [NSMUtableArray array];

This is the same with [[NSMutableArray alloc] init] in ARC.

Don't understand the message. The code posted above shows how to create a temporary array, load it and show its contents. The 'self->mymutarr' won't achieve your objective.

My variable is “global”, not a local function var. This is the reason i write "self->”.
I want to get the value from the NSMutableArray defined in @interface.

Brian




--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@... To access the list archives, go to: http://freegroups.net/groups/futurebasic/



Victor


--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@... To access the list archives, go to: http://freegroups.net/groups/futurebasic/