this is the method of traversing and removing the specified type subview:
- (void)refresh {
for (UIView *view in self.subviews) {
if ([view isMemberOfClass:[GoodListThemeView class]] || [view isMemberOfClass:[SingleGoodsThemeView class]]) {
[view removeFromSuperview];
}
}
}
when this method is called, the memory changes are as follows:
if I commented out the code [view removeFromSuperview];
, there would be no such phenomenon of memory exploding and then plummeting.
I guessed that a large number of temporary objects were generated in that for loop, so I used autoreleaserpool:
- (void)refresh {
for (UIView *view in self.subviews) {
@autoreleasepool {
if ([view isMemberOfClass:[GoodListThemeView class]] || [view isMemberOfClass:[SingleGoodsThemeView class]]) {
[view removeFromSuperview];
}
}
}
}
but memory suddenly soars and then falls.