الهدف-C: تسرب الذاكرة أم لا مع تعيين متعدد مع Autorelease؟
-
25-09-2019 - |
سؤال
إذا قمت بالشيء التالي ، فهل سيجعل هذا تسرب الذاكرة؟
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 ، بغض النظر عما إذا كان المتغير الذي يحمل مؤشراتهم قد تم تغييره أم لا.
لا تنتمي إلى StackOverflow