id copiedArray = [NSMutableArray arrayWithCapacity:3];
This will create an autoreleased object. You shouldn't release autoreleased objects.
Either remove your release call, or change that line to this:
id copiedArray = [[NSMutableArray alloc] initWithCapacity:3];
That being said, consider using Automatic Reference Counting (ARC).
From Advanced Memory Management Programming Guide:
You own any object you create
You create an object using a method whose name begins with
alloc
,new
,copy
, ormutableCopy
(for example,alloc
,newObject
, ormutableCopy
).You can take ownership of an object using retain
A received object is normally guaranteed to remain valid within the method it was received in, and that method may also safely return the object to its invoker. You use
retain
in two situations: (1) In the implementation of an accessor method or an init method, to take ownership of an object you want to store as a property value; and (2) To prevent an object from being invalidated as a side-effect of some other operation.When you no longer need it, you must relinquish ownership of an object you own
You relinquish ownership of an object by sending it a
release
message or anautorelease
message. In Cocoa terminology, relinquishing ownership of an object is therefore typically referred to as “releasing” an object.You must not relinquish ownership of an object you do not own
This is just corollary of the previous policy rules, stated