Leak problem in Cocoa NSMutableArray/objectEnumerator
Leak problem in Cocoa NSMutableArray/objectEnumerator
- Subject: Leak problem in Cocoa NSMutableArray/objectEnumerator
- From: Professor Leslie Smith <email@hidden>
- Date: Fri, 27 Aug 2004 11:52:23 +0100
- Organization: University of Stirling
Hi:
Here is example code: method startButton is called when the start button
is pressed.
NSMutableArray *MyArray is declared in the header.
It is created using
[NSMutableArray arrayWithCapacity: 100] ;
and then filled with NSNumber objects.
startbutton repeatedly traverses the array, reporting every million
traverses:
- (void) startButton: sender
{
int i,j,k ;
// repeatedly traverses the array
for (i=0;i<10000;i++)
{
for (j=0;j<1000000;j++)
k = [self traverseArray] ;
// report every 1 000 000 operations
NSLog(@"Done %i M Iterations", i) ;
}
}
and traverseArray looks like
- (int) traverseArray
{
id anObject ;
int j ;
// traverse array
NSEnumerator *enumerator = [MyArray objectEnumerator] ;
while (anObject = [enumerator nextObject]) {
j = [anObject intValue] ;
/* code to act on each element as it is returned */
}
return j ;
}
What happens is
... (lines deleted)
2004-08-27 09:57:01.693 tester[2662] Done 52 M Iterations
2004-08-27 09:57:26.595 tester[2662] Done 53 M Iterations
Program received signal: "SIGTRAP".
*** malloc: vm_allocate(size=1069056) failed (error code=3)
*** malloc[2662]: error: Can't allocate region
I don't think this program should not fail at all.
It looks as though the NSMutableArray objectEnumerator is not being
deallocated entirely.
This is a real difficulty if one is to use NSMutableArray as one would
wish - in my own case, in a long simulation.
I have reported this as a bug: (3778469).
I haven't had time to try it out on a plain NSArray.
Is this a known problem? Has anyone a workaround? (preferably short of
using C arrays).
(Or have I simply misunderstood something?)
--
Professor Leslie S. Smith,
Dept of Computing Science and Mathematics,
University of Stirling,
Stirling FK9 4LA, Scotland
email@hidden
Tel (44) 1786 467435 Fax (44) 1786 464551
www http://www.cs.stir.ac.uk/~lss/
UKRI IEEE NNS Chapter Chair: http://www.cs.stir.ac.uk/ieee-nns-ukri/
--
The University of Stirling is a university established in Scotland by
charter at Stirling, FK9 4LA. Privileged/Confidential Information may
be contained in this message. If you are not the addressee indicated
in this message (or responsible for delivery of the message to such
person), you may not disclose, copy or deliver this message to anyone
and any action taken or omitted to be taken in reliance on it, is
prohibited and may be unlawful. In such case, you should destroy this
message and kindly notify the sender by reply email. Please advise
immediately if you or your employer do not consent to Internet email
for messages of this kind.
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.