假设我有一个名为"foo"的对象,另一个名为"bar"的对象作为属性.
当"foo"解除分配时,它会自动删除对"bar"的所有引用,以便"bar"也可以解除分配吗?或者"foo"deallocate和"bar"漂浮在某个地方的记忆中?即使所有"bar"的引用都在"foo"中定义.
提前致谢.
iphone garbage-collection memory-management objective-c dealloc
我已经测试了我的所有viewControllers dealloc方法.并且所有这些都在调用popViewControllerAnimated时被正确调用.
但是只有一个控制器的dealloc方法没有被调用.我无法弄清楚这个问题.
在推送到该控制器时,我已正确编写以下代码:
AController *contr = [AController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:contr animated:YES];
[contr release];
Run Code Online (Sandbox Code Playgroud)
当我从控制器回来时,我写道:
[self.navigationController popViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
这是非常奇怪的行为,因为这段代码写在许多控制器上并且工作正常.
我正在使用自动参考计数.我有一个自定义UIViewController子类,每当我-presentViewController: animated:completion:从NSLogsuperview 调用或删除它的视图时,我想要"我被释放"这样的东西,所以我知道视图控制器已成功删除.我-dealloc在视图控制器中实现了该方法.然而,我开始了一个测试项目,其中我只有两个UIViewController实例(没有保留周期),并且-dealloc当我按模式推送第二个UIViewController或当我删除超级视图或从父视图控制器中删除它时,都没有调用.我错过了什么吗?在我原来的项目中(不是测试用例),仪器向我展示了那些控制器留下了我无法摆脱的内存占用.
objective-c uiviewcontroller dealloc ios automatic-ref-counting
在iOS中,我从当前的viewController弹出到前一个,但它不会进入dealloc.
这是因为还有另一个指向当前viewController的指针,在不同的viewController中还是在当前的viewController中?
这是我弹出前一个视图的地方:
- (IBAction)fileUploadCancelTouched:(UIButton *)sender {
[self.fileToUpload cancel];
[self.view hideToastActivity];
[self.greenprogressBar removeFromSuperview];
[self.subView removeFromSuperview];
self.fileUploadCancelButton.hidden = YES;
if (self.commandComeBackToFinalScreen == 1) {
[self.navigationController popViewControllerAnimated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的dealloc功能:
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
self.greenprogressBar = nil;
self.fileUploadCancelButton = nil;
self.fileToUpload = nil;
[buttonHome_ release];
[buttonTestMeAgain_ release];
[buttonMarkMyTest_ release];
[examId_ release];
[sender_ release];
self.ob = nil;
[_fileUploadCancelButton release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud) 我有一个A类的对象a1,我想找到所有对象a1具有强引用的对象.
有办法吗?
我想知道这个的原因是因为,a1似乎没有被释放.
objective-c dealloc ios xcode-instruments automatic-ref-counting
我一直在努力解决这个问题,因为某些原因我的SKScenes没有正确解除分配,这导致内存增长有限,因为每次我退出并进入场景时内存会跳起来.这意味着在玩了10轮比赛之后App崩溃了.据我所知,经过多次检查后,我没有任何保留周期或强烈引用场景本身,虽然我知道纹理被缓存并保存在内存中,一旦预加载,内存不应该每次都上升.
这就是我在viewcontroller中设置skview和第一个场景的方法:
-(void)loadStartScreen{
SKView *theView = (SKView *) self.view;
theView.showsFPS = YES;
theView.showsNodeCount = YES;
//Sprite Kit applies additional optimizations to improve rendering performance
theView.ignoresSiblingOrder = YES;
// Create and configure the scene.
MainMenuScene *theScene = [MainMenuScene sceneWithSize:theView.bounds.size];
theScene.scaleMode = SKSceneScaleModeAspectFill;
theScene.backgroundColor = [UIColor grayColor];
// Present the scene
[theView presentScene:theScene];
Run Code Online (Sandbox Code Playgroud)
这是我的MainMenuScene中的代码,用于创建并移动到下一个场景:
SKScene *theScene;
SKTransition *theTransition;
switch (theTag.intValue) {
case 0: // start game
// stop music
[[appDelegate musicPlayer]stop];
theScene = [[GameLevelScene alloc] initWithSize:self.view.bounds.size];
// transition type
theTransition = [SKTransition …Run Code Online (Sandbox Code Playgroud) 我一直在努力解决这个问题,但是我无法找到解决方案:
我有一个支持所有设备系列的iOS 9应用程序,使用大小类并使用Swift 2.0进行编程.我正在使用a UISplitViewController,一切都按照我的要求工作,除了在崩溃的环境中(例如在iPhone上).
Master-ViewController是在UITableViewController选择单元格时触发替换segue的.在折叠环境中,这意味着detailViewcontroller被推送到屏幕上.在UISplitViewController视觉上表现有点像UINavigationController.但是,当我使用后退按钮或滑动手势关闭detailViewController时,在Master-ViewController中触发新的替换segue之前,它不会被释放.
我认为这是一个特征UISplitViewController,因为它最初设计为显示彼此相邻的两个内容.然而,在崩溃的环境中,我希望我UISplitViewController的行为像一个简单的UINavigationController,在弹出时释放先前推送的detailviewController.
viewControllers在弹出detailViewController后,我一直在尝试手动更改splitViewController的属性:
if let firstVc = self.splitViewController?.viewControllers.first {
self.splitViewController?.viewControllers = [firstVc]
}
Run Code Online (Sandbox Code Playgroud)
但这没有用.简单地用一个空的"Dummy"-ViewController替换detailViewController也不起作用,因为它会自动动画转换.和UISplitViewControllerDelegate我一起玩并没有帮助我...
有没有解决方案(也许简单?:)),我太盲目了?
当尝试在 iOS swift 中对我的自定义对象进行编码时,从 Xcode 8.3 获取此错误
无法识别的选择器发送到实例 0x60800166fe80 *** -[NSKeyedArchiver dealloc]:警告:NSKeyedArchiver 在没有调用 -finishEncoding 的情况下被释放。
我的代码是这样的:
导入 UIKit 导入基础
class Place: NSObject {
func setCustomObject(CustomObject obj:Any,Key key:String) {
let encodedObject : Data = NSKeyedArchiver.archivedData(withRootObject: obj)
UserDefaults.standard.set(encodedObject, forKey: key)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用这堂课:
https://github.com/alexleutgoeb/ALPickerView
由于我转换为ARC,因此在点击pickerview几次后出现此错误:
2011-10-18 14:10:19.424 MappingApp[3398:10d03] An instance 0x73c7cd0 of class CustomTapGestureRecognizer was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: <NSKeyValueObservationInfo 0x5d93430> (<NSKeyValueObservance 0x5d933f0: Observer: 0x5d66eb0, Key path: state, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x746b180>)
Run Code Online (Sandbox Code Playgroud)
该错误指向CustomTapGestureRecoginizer类和此方法的最后一行:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { …Run Code Online (Sandbox Code Playgroud) cocoa-touch dealloc ios observer-pattern automatic-ref-counting
我有cocos2d的问题.我做了一个接受触摸的课程.类的子类CCLayer和init看起来像这样:
- (id)initWithFrame:(CGRect)frameSize
{
self = [super init];
if (self)
{
frame = frameSize;
size = frame.size;
origin = frame.origin;
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
所以一切都很简单.frame,size并且origin是类变量,但这现在无关紧要.所以我注册了我的班级女巫touchDispatcher,让我可以处理.触摸处理完成如下:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
//Some touch logic which i need.
}
Run Code Online (Sandbox Code Playgroud)
在dealloc我发布所有保留的信息并取消注册touchDispatcher.但从dealloc未被称为.如果我不与注册touchDispatcher的dealloc正确调用.如果重要的话,这个类作为子类添加到另一个CCLayer子类中,并且在该类中dealloc我释放了这个类.
我错过了什么?
dealloc ×10
ios ×7
objective-c ×3
iphone ×2
cocoa-touch ×1
crash ×1
deinit ×1
delegates ×1
encode ×1
lifecycle ×1
skscene ×1
sprite-kit ×1
swift ×1
touch ×1