小编Sag*_*ari的帖子

了解仪器进行内存泄漏检查 - iPhone

替代文字

上面给出的图像是我的应用程序泄漏.

在这里,我想了解一下,在扩展细节中 - 您可以看到不同的颜色,如浅绿色,浅粉色,浅棕色,浅紫色.

每种颜色表示什么?

现在另一个困惑是"如何找到造成内存泄漏的代码?"

高达内存泄漏的限制 - 实际的iPhone可以继续使用.(假设10个字节没问题,20个字节没问题,200个字节有问题)

  • 每种颜色表示什么?
  • 哪种颜色表示我们的代码/从哪个细节我们可以获得我们分配对象的代码并忘记解除它?

(例如 - 详细点击UIKit第二个单元格 - 我们无法获取代码)

  • 为什么我们必须解决所有泄漏? - 即使是一次泄密也可以蚕食iPhone?
  • 为什么iPhone允许泄漏留在内存中?/为什么在终止申请后垃圾收集不会自动完成?
  • 如果我尝试释放应根据仪器解除分配的对象,我的应用程序会异常终止.如果我不dealloc,我的应用程序运行完美,如何?
  • 为什么建议您在视图中等待最多10秒或更长时间,如果有泄漏,仪器会检测到泄漏?

iphone memory-leaks instruments

6
推荐指数
2
解决办法
6905
查看次数

在iPhone的UINavigation酒吧背景

我已将以下代码应用于我的应用程序以更改导航栏图像.

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
[self setNavigationBarTitle];
}
-(void)setNavigationBarTitle {
UIView *aViewForTitle=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)] autorelease];
UIImageView *aImg=[[UIImageView alloc] initWithFrame:CGRectMake(-8, 0, 320, 45)];
aImg.image=[UIImage imageNamed:@"MyTabBG.png"];
[aViewForTitle addSubview:aImg]; [aImg release]; 
UILabel *lbl=[[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 305, 45)] autorelease];
lbl.backgroundColor=[UIColor clearColor]; lbl.font=[UIFont fontWithName:@"Trebuchet MS" size:22];
lbl.shadowColor=[UIColor blackColor]; [lbl setShadowOffset:CGSizeMake(1,1)];
lbl.textAlignment=UITextAlignmentCenter; lbl.textColor=[UIColor whiteColor]; lbl.text=@"Mobile Tennis Coach Overview";
[aViewForTitle addSubview:lbl];
[self.navigationItem.titleView addSubview:aViewForTitle];
}
Run Code Online (Sandbox Code Playgroud)

见下图.你可以看到我面临的问题.

替代文字


替代文字

我的应用程序的每个视图控制器都有上述方法来设置导航栏背景.

然而,当我将一个新的视图控制器推送到我的应用程序时.将出现后退按钮.

我需要后退按钮才会出现.但是图像应该在后面的按钮后面.

现在我有点困惑.

你能帮我解决这个问题吗?

在此先感谢您与我分享您的知识.

非常感谢.

iphone xcode uinavigationbar uinavigationitem

6
推荐指数
2
解决办法
9420
查看次数

更新XCode项目模板详细信息

以前所有文件头都显示如下.

//  Created by ABC_User_Name on 10/31/11.
Run Code Online (Sandbox Code Playgroud)

我已将用户名从ABC_User_Name修改为XYZ_User_Name.

现在,即使在注销并再次登录后,我在所有项目模板中都找到了相同的标题.如何使用当前用户名更新这些模板?

我需要手动修改所有这些吗?

iphone xcode project-template ios

6
推荐指数
1
解决办法
1446
查看次数

示例代码中的AVFoundation.Framework中的静态void指针

我只是通过示例代码AVFoundation.Framework- > AVSimpleEditoriOS&我发现以下行,我无法理解.

static void *AVSEPlayerItemStatusContext = &AVSEPlayerItemStatusContext;
static void *AVSEPlayerLayerReadyForDisplay = &AVSEPlayerLayerReadyForDisplay;
Run Code Online (Sandbox Code Playgroud)

考虑以下

static void *AVSEPlayerItemStatusContext = nil;
static void *AVSEPlayerLayerReadyForDisplay = nil;
Run Code Online (Sandbox Code Playgroud)

在上面的两行中,我可以看出那些是2个静态的void/generic指针,带有一些奇特的名字.

现在回到这两行,我再次粘贴在这里,

static void *AVSEPlayerItemStatusContext = &AVSEPlayerItemStatusContext;
static void *AVSEPlayerLayerReadyForDisplay = &AVSEPlayerLayerReadyForDisplay;
Run Code Online (Sandbox Code Playgroud)

上面是否意味着,2个静态void/generic指针存储它自己的引用?为什么它需要在什么意义上呢?

我只需要很少的指导来学习这种编码模式.等待知识.

static objective-c avfoundation ios

6
推荐指数
1
解决办法
627
查看次数

在iPhone中使用NSData的内存泄漏问题

内存泄漏问题 - NSConcreteData

// to set tip - photo in photo frame    
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]];
UIImage *cellThumbImg;
if([data length]>0){ cellThumbImg=[UIImage imageWithData:data];} else { cellThumbImg=[UIImage imageNamed:@"130X90.gif"]; }
UIImageView *imgView=[[UIImageView alloc]initWithImage:cellThumbImg]; imgView.frame=photoFrame;
(cellThumbImg.size.height>=58 || cellThumbImg.size.width>=58 ) ? [imgView setContentMode:UIViewContentModeScaleToFill] : [imgView setContentMode:UIViewContentModeCenter] ;
[cell.contentView addSubview:imgView]; 
[imgView release]; 
Run Code Online (Sandbox Code Playgroud)

我的问题与这个问题非常相似,

iPhone - 内存泄漏 - NSData dataWithContentsOfUrl和UIWebView

甚至,我已经将以下代码添加到我的应用程序已完成启动中,如下所示.以下代码用于设置零容量的sharedCache内存.它几乎会删除我的应用程序中的NSConcreteData泄漏.但内存泄漏.

- (void)applicationDidFinishLaunching:(UIApplication *)application {       
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
[window makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)

我从堆栈溢出中找不到任何解决这类问题的方法.

如果你能回答,我将感激你.

提前致谢.

iphone cocoa-touch memory-leaks

5
推荐指数
3
解决办法
5628
查看次数

在iphone应用程序中的线程之后调度线程

我想在线程完成后安排一个线程.

可能吗 ?怎么样?

例如(指明我的需要)

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    // 1. response - schedule myThread 
    // 2. response - schedule a new thread which will be executed after myThread
    // 3. response - schedule a new thread which will be executed after second thread
    // .....
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa cocoa-touch objective-c nsthread

5
推荐指数
1
解决办法
1762
查看次数

强制申请终止iPhone

我正在开发一个完全基于Web数据的iPhone应用程序.

如果它没有连接到互联网,该应用程序是没有用的.

所以,我想在找不到连接时终止应用程序.

NSURL *tmpURl=[NSURL URLWithString:[NSString stringWithFormat:@"%@search.php",[iGolfAppDelegate getServerPath]]];
    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
    con=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if(con){
        myWebData=[[NSMutableData data] retain];    
    } else { 
        //Yes I will provide two buttons on alertview "retry" & "close", & when user
        //taps on "close" => application should terminate.
        // i will send alertview & when user taps on button close then
        // what to write for terminating application?
        // Ok Ok. Don't terminate. User will terminate.
        // user is owner of iPhone 
        // let him …
Run Code Online (Sandbox Code Playgroud)

objective-c ios

5
推荐指数
4
解决办法
8264
查看次数

UIButton - 我们应该发布还是不发布?

我想动态地在视图上添加一个按钮.这是代码.

UIButton *x=[UIButton buttonWithType:UIButtonTypeRoundedRect];
Run Code Online (Sandbox Code Playgroud)

在这里,我没有使用"alloc"功能.

本声明的问题如下.

  • 如果我们在相同的情况下使用imageview,我们必须创建一个临时imageview添加到您当前的视图并释放它.按钮怎么办?
  • 如何分配和取消分配按钮?
  • 如果分配了按钮?如何管理内存?
  • 现在当我使用[x release]; - 是对还是错?

iphone objective-c interface-builder uibutton cocoa-design-patterns

5
推荐指数
1
解决办法
3077
查看次数

如何从资产中确定特定文件的绝对路径?

在iPhone应用程序中,我只写了一行来获取特定文件的完整路径(如下所示).

NSString *strPath=[[NSBundle mainBundle] pathForResource:@"myjavascript" ofType:@"js"];
Run Code Online (Sandbox Code Playgroud)

我的问题是如何获取位于Android的Assets文件夹下的特定文件的完整路径.

示例图像.

替代文字

javascript android android-assets

5
推荐指数
1
解决办法
9812
查看次数

检查iOS模拟器类型和版本

我有以下代码片段来检测iOS设备.

NSString * platformNSString () {
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);
    return platform;
}

NSString * platformString () {
    NSString *platform = platformNSString();

    // iphones
    if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (CDMA)";
    if …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ipad ios ios-simulator

5
推荐指数
1
解决办法
2286
查看次数