我使用的是UISplitViewController上ARC.
我在我的设置中设置了控制器AppDelegate,然后将其设为rootViewController.我确保做到了property:
@property (strong, nonatomic) UISplitViewController *splitViewController;
Run Code Online (Sandbox Code Playgroud)
viewControllers首次创建时,使用属性设置根和详细信息可正常工作.并且在第二次设置时它再次正常工作,但是第三次尝试设置viewControllers属性时我遇到了崩溃.
以下是我设置的方法:
Screens *edit = [[Screens alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *c = [[UINavigationController alloc] initWithRootViewController:edit];
if ([Utility isIpad]) {
Map *a = (Map *)[[MyAppDelegate instance].splitViewController.viewControllers objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObjects:a, c, nil];
UISplitViewController *splitView = [MyAppDelegate instance].splitViewController;
splitView.viewControllers = viewControllers;// <--- Crashes here
} else {
[self presentModalViewController:c animated:YES];
}//end
Run Code Online (Sandbox Code Playgroud)
当我尝试设置viewControllers属性时为什么会崩溃?它几乎似乎被释放了,但我知道它splitViewController仍然存在......
这可能与ARC有关吗?
堆栈跟踪:

cocoa-touch objective-c uisplitviewcontroller ios automatic-ref-counting
需要有ARC知识的人来帮助我.
基本上,我已经在我的班级中声明了一些变量
@interface Class{
NSString* one;
NSString* two;
}
@property(nonatomic,weak) NSString* one;
Run Code Online (Sandbox Code Playgroud)
如您所见,我可以将弱标识符设置为NSString* one.但是,我不需要getter/setter/synthesizer,NSString* two因为它只是一个常见的变量.如何weak为其设置标签以便释放内存?还是自动设定?
我添加了运行Admob SDK所需的所有文件和框架,但问题是ARC ......
我的项目使用ARC,但AdMob文件不使用ARC.我知道您可以通过项目菜单下的"编译源"部分 - >目标(应用程序名称) - >构建阶段来禁用特定文件上的ARC
问题是AdMob文件未显示在"编译源"部分或任何其他部分中.您可以在Project Navigator中查看我的AdMob文件夹...
为什么这些文件不会出现,所以我可以禁用它们?

所以我的理解是,如果该方法没有实现初始化对象的新实例,那么在方法名称中使用init是不可取的.但是,单例类型的情况是什么?如果我做这样的事情:
+ (MyClass*) sharedInstance {
__block MyClass *sharedInstance = nil;
static dispatch_once_t once_token;
dispatch_once(&once_token, ^{
sharedInstance = [[MyClass alloc] init];
});
return sharedInstance;
}
Run Code Online (Sandbox Code Playgroud)
然后有另一种方法:
- (void) initializeInstance {
// Do some stuff
// Never call the init method
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做,是否会有额外的保留周期或其他奇怪的ARC行为?
我有兴趣了解如何在ARC紧密循环下最好地处理内存管理.特别是,我有一个我正在编写的应用程序,它有一个while很长时间的循环,我注意到尽管已经实现了(我相信是)ARC中的最佳实践,但堆仍然存在无限增长.
为了说明我遇到的问题,我首先设置以下测试以故意失败:
while (true) {
NSMutableArray *array = [NSMutableArray arrayWithObject:@"Foo"];
[array addObject:@"bar"]; // do something with it to prevent compiler optimisations from skipping over it entirely
}
Run Code Online (Sandbox Code Playgroud)
使用"分配"工具运行此代码和分析表明内存使用量不断增加.但是,@autoreleasepool如下所示,立即解决问题并保持内存使用的良好和低:
while (true) {
@autoreleasepool {
NSMutableArray *array = [NSMutableArray arrayWithObject:@"Foo"];
[array addObject:@"bar"];
}
}
Run Code Online (Sandbox Code Playgroud)
完善!这一切似乎都运行良好 - 它甚至可以正常工作(如预期的那样)用于使用创建的非自动释放的实例[[... alloc] init].一切正常,直到我开始涉及任何UIKit课程.
例如,让我们创建一个UIButton并看看会发生什么:
while (true) {
@autoreleasepool {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectZero;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,内存使用量无限增加 - 实际上,它似乎@autoreleasepool没有任何效果.
所以问题是为什么 …
我正在使用最新的SDK和ARC开发iOS应用程序.
我有这个变量:
NSMutableArray* _previewImageBuffer;
Run Code Online (Sandbox Code Playgroud)
而这种方法:
- (void)shutdown
{
[self stop];
_previewImageBuffer = nil;
}
Run Code Online (Sandbox Code Playgroud)
是对的_previewImageBuffer = nil;吗?如果我这样做,_previewImageBuffer`中分配的内存会发生什么?这是内存泄漏吗?
我想释放这个对象,因为我需要释放它使用的内存.
如果我在iPhone代码中实现以下内容:
NSString* soundPath = [[NSBundle mainBundle] pathForResource:soundFile ofType:@"wav"];
SystemSoundID feedbackSound;
AudioServicesCreateSystemSoundID((__bridge CFURLRef) [NSURL fileURLWithPath:soundPath], &feedbackSound);
AudioServicesPlaySystemSound(feedbackSound);
Run Code Online (Sandbox Code Playgroud)
我是否真的必须释放"feedbackSound",因为它是C代码?它会泄漏吗?
我正在使用ARC/iOS 6.
我在弧项目中有一个tableView.当我滚动它甚至一秒钟时,所有数据都被隐藏或消失.
我通过Strong属性从另一个控制器传递数据.
CTableViewController* cTableVc=[[CTableViewController alloc] initWithNibName:@"CTableViewController" bundle:nil];
cTableVc.cArray=[[NSArray alloc] initWithArray:[MyVC pathForAllCardsInDocumentDiretory]];
cTableVc.view.frame=CGRectMake(0, 0, cTableVc.view.frame.size.width, cTableVc.view.frame.size.height);
[self.view addSubview:cTableVc.view];
Run Code Online (Sandbox Code Playgroud)
这是我的财产
@property(strong, nonatomic) NSArray* cArray;
Run Code Online (Sandbox Code Playgroud)
CTableViewController.m tableView方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_cardArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"CTableViewCell";
CTableViewCell *cell = (CTableViewCell *) [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects …Run Code Online (Sandbox Code Playgroud) 在我的代码中,我正在创建一个Core Foundation对象,从Apple文档中我知道
“ Core Foundation对象的寿命由其引用计数决定” https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Articles/lifecycle.html
因此,我非常怀疑核心基础对象是由ARC发布还是我们需要通过编写CFRelease(myobject)进行发布
我正在使用Xcode 6.4,目前在我的代码中没有使用任何CFRelease(myobject)释放我的Core Foundation对象,但是我仍然找不到在xcode工具中的任何内存泄漏(泄漏)。
因此,我的问题是ARC是否将负责发布Core Foundation对象。
当我刚遇到一个类似的声明时,
回想一下,ARC仅处理Objective-C对象。它不管理非Objective-C对象的CoreFoundation对象的保留和释放。http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode
因此,如果有人遇到相同的问题并找到一种解决方案,请与我们分享...
提前致谢..
memory-leaks memory-management core-foundation xcode-instruments automatic-ref-counting
即使在阅读了Swift关于ARC的文档之后,我仍然无法理解为什么属性设置为nil,即使它在函数中被实例化也是如此.我有以下示例代码:
import UIKit
class ItemListViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView()
}
}
Run Code Online (Sandbox Code Playgroud)
以下是测试运行的示例代码:
import XCTest
@testable import PassionProject
class ItemListViewControllerTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class. …Run Code Online (Sandbox Code Playgroud) objective-c ×8
ios ×7
cocoa-touch ×3
ios6 ×2
iphone ×2
admob ×1
c ×1
memory-leaks ×1
singleton ×1
swift ×1
uitableview ×1
weak ×1
xcode ×1
xctest ×1