objective c - iOS: is it possible to create a matrix of NSObjects? -



objective c - iOS: is it possible to create a matrix of NSObjects? -

since objective c superset of c it' possible utilize malloc/free primitive types create matrix of nxm elements. wouldn't because may cause bugs , memory leaks. lastly point still true? arc provide releasing of c types?

int** matrix=(int**)malloc(n*sizeof(int*)); for(int i=0; i<n; i++) matrix[i]=(int*)malloc(m*sizeof(int));

is possible objective-c way? found nsmatrix it's mac, not ios.

do arc provide releasing of c types?

no, not. arc stands automated reference counting, meaning works reference-counted objects.

since malloc/free deals "plain" freestore allocations, memory blocks receive malloc not eligible arc.

this not mean, however, couldn't accomplish grade of automation in managing malloc-allocated memory "piggybacking" on arc:

make own class has instance variable pointing matrix, , allocate matrix in designated initializer. add dealloc method calls free on allocated memory blocks.

now have reference-counted class holds matrix. whenever arc instructs class deallocate, memory held matrix gets released well:

@interface matrix : nsobject @property (nonatomic, readonly) int** data; -(instancetype)initiwithrows:(nsuinteger)rows andcolumns:(nsuinteger)cols; -(void)dealloc; @end

ios objective-c c matrix memory-leaks

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -