将 UIImageView 添加到另一个窗口视图时如何管理内存?
因为我认为我最近的另一篇文章吓跑了所有人(
将 UIImageView 添加到另一个窗口视图时,如何管理内存和释放内存?
即我在一个视图中创建 UIImageView,并将其添加为另一个窗口视图中的子视图。电视正在使用另一个窗口。
现在我有:
mapImageViewEx = [[UIImageView alloc] init];
// I think you can ignore these two things below
CGPoint p = mapScrollView.contentOffset;
mapImageViewEx.frame = CGRectMake((p.x*-1), (p.y*-1), mapImageView.frame.size.width, mapImageView.frame.size.height);
NSString *mapExFileLocation = [[NSBundle mainBundle] pathForResource:[map_List objectAtIndex:mapNum] ofType:@"png"];
NSData *mapExIMGData = [NSData dataWithContentsOfFile:mapExFileLocation];
mapImageViewEx.image = [UIImage imageWithData:mapExIMGData];
// finds the other window's view controller's view
UIView *containerExViewP = (UIView*)[del.switchExVC.view viewWithTag:9000];
// adds it
[containerExViewP addSubview:mapImageViewEx];
我遇到的问题是每次我退出视图时它都会不断累积内存使用量。在 iPad 屏幕视图的 dealloc 中释放图像不会执行任何操作。
Since I think I scared everyone away with my other recent post ( Memory management when adding a UIImageView to another viewController's view from another viewController's view ) and I'm running out of time, I'd just like to ask this in simpler terms. If you want to know I'm doing with more detail, refer to the other post.
How do you manage memory, and releasing, when adding a UIImageView to another windows view?
i.e. I'm creating a UIImageView in one view, and adding it as a subview in another windows view. The other window is being used by a TV.
Right now I have:
mapImageViewEx = [[UIImageView alloc] init];
// I think you can ignore these two things below
CGPoint p = mapScrollView.contentOffset;
mapImageViewEx.frame = CGRectMake((p.x*-1), (p.y*-1), mapImageView.frame.size.width, mapImageView.frame.size.height);
NSString *mapExFileLocation = [[NSBundle mainBundle] pathForResource:[map_List objectAtIndex:mapNum] ofType:@"png"];
NSData *mapExIMGData = [NSData dataWithContentsOfFile:mapExFileLocation];
mapImageViewEx.image = [UIImage imageWithData:mapExIMGData];
// finds the other window's view controller's view
UIView *containerExViewP = (UIView*)[del.switchExVC.view viewWithTag:9000];
// adds it
[containerExViewP addSubview:mapImageViewEx];
Problem I'm having is that it keeps stacking up memory use every time I exit the view. Releasing the image in the iPad screen view's dealloc does nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
为
自动释放意味着引用计数将在将来的某个未知时刻减少。
addSubview 会增加计数,所以你不必担心它。
只要正确处置父视图,mapImageViewEx就会被释放。
change
to
autorelease means that the reference count will be decremented at some unknown point in the future.
the addSubview will increment the count, so you don't have to worry about it.
As long as the parent view is properly disposed of, mapImageViewEx will be released.