nsmutablearray - Storing pointers to objects in array in Objective c -


After

I am using this code to create some items and then store them in an array {Pre int ( ii = 0; iy & lt; 5; iy ++} for

  {int ix = 0; z & lt; 5; z ++} {TerrainHex * myObject = [[ TerrainHex alloc] initWithName: (@ "grassHex example 10000") Width: MGameWidth height: mGameHeight index: ix index: iy]; MyObject.myImage.y + = 100; [Terrain hexarered object: myobacter]; [Self Combined: (id) myObject.myImage]; }} NSLog (@ "% lu", size (TerrainHexArray));   

Some questions.

  1. The log is displaying only 4, which does not make sense, it should not be 5x5, I 25?
  2. Am I making 25 different object points here or just using it again? I am trying to save all 25 points in an array.
  3. I am using ARC, but what is there to release anything there?

    itemprop = "text">

    1. sizeof () Variable is TerrainHexArray which (probably) tells the size of the indicator byte for an NSMutableArray. Assuming 32-bit systems, pointers are 32 bits which are 4 bytes. Instead you should use [TerrainHexArray count] . This is the method that gives the number of objects in the array.

    2. You are creating 25 object instances, not more than one, myObject is just a variable that holds a pointer for a given object . By working, the object to change it is not erased before it pointed out (though the ARC takes care of it).

    3. No, ARC takes care of memory management for you.

      A nitpick: Assume that TerrainHexArray is an example of NSArray, then you should not capitalize the first letter. This language is not required, but it is a conference to redeem class names, but they use a lower case first letter for variable names. terrainHexArray will be more appropriate and will make the code more readable.

Comments