الهدف-C: تسرب الذاكرة أم لا مع تعيين متعدد مع Autorelease؟

StackOverflow https://stackoverflow.com/questions/4607305

سؤال

إذا قمت بالشيء التالي ، فهل سيجعل هذا تسرب الذاكرة؟

SomeClass* tmp;
NSDate* thetmpdate;

tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date

tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date

tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date
هل كانت مفيدة؟

المحلول

لا ، لا يوجد تسرب في الكود الذي نشرته. سيتم توضيح جميع الكائنات عند مسح تجمع Autorelease ، بغض النظر عما إذا كان المتغير الذي يحمل مؤشراتهم قد تم تغييره أم لا.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top