Memory leak on iOS

Hm, something does indeed seem to be wrong here. i see the following retain/releases:

#	Event Type	∆ RefCt	RefCt	Timestamp	Responsible Library	Responsible Caller
0	Malloc	+1	1	00:04.828.966	ConsoleApplication17	+[NSObject allocWithZone:]

1	Retain	+1	2	00:04.834.515	ConsoleApplication17	+[NSObject allocWithZone:]
2	Retain	+1	3	00:04.834.518	ConsoleApplication17	-[__ConsoleApplication17_Program Main:]

3	Release	-1	2	00:04.834.518	ConsoleApplication17	-[__ConsoleApplication17_Program 
4	Release	-1	1	00:04.834.519	ConsoleApplication17	-[__ConsoleApplication17_Program 

what’s odd is our generate code dopes the right thing (it gets/expects a retained object, retains it, releases it twice. So those zero out. But for some reason +[NSObject allocWithZone:] already does a second retain — i.e. the object we get back for allocating it already has a retain out of 2, it seems — which we don’t know about and thus ofc don’t compensate for.

I’ll have to pass this to carlo to have a look on compiler level, whats going on here.

very oddly, if i remove the private NSMutableArray data = new NSMutableArray withCapacity(1024/**1024*/);, the then object deallocates fine. It seems that having that field there causes the extra retain somehow,

Actually…

yep, this sound like it’s known issue “bugs://72928: Nougat: pre-initialized field causes class to not be deallocated properly” from thread No memory release for UViewController when variable is initialized.