0
請參閱下面的方法內存雖然釋放的對象警告
-(void)addScrollView{
[self selectData];
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(5, 00, 320, 480)];
int counter=5;
float y=40.0f;
int fullLength=[photoArray count];
int horizontal=320;
int vertical=(fullLength/4)*80;
int c1=1;
for(int c=0;c<[photoArray count];c++){
PhotoData *d=[photoArray objectAtIndex:c];
//NSLog(d.photoPath);
if(c1==5){
counter=5;
y=y+80.0f;
c1=1;
}
UIImage *img1=[[UIImage alloc]initWithContentsOfFile:d.photoPath];
UIButton* button = [[UIButton alloc] init];
button.tag=c;
[button setBackgroundImage:img1 forState:UIControlStateNormal];
[button setFrame:CGRectMake(counter, y, 70.0, 70.0)];
[button addTarget:self action:@selector(showDetail:)
forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
counter=counter+78.0f;
c1++;
[img1 release];
[button release];
}
[scrollView setContentSize:CGSizeMake(horizontal, vertical+200)];
[self.view addSubview:scrollView];
[scrollView release];
}
也
-(void)selectData{
//This method is defined to retrieve data from Database
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
//Obtained the path of Documennt directory which is editable
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"memory.sql"];
//memory.sql is sqlite file which is used as local database
photoArray=[[NSMutableArray alloc]init];
NSString *dbPath=filePath;
sqlite3 *database;
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from photo ";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
//sqlite3_bind_int(compiledStatement, 1,memoryId);
//(compiledStatement, 1, [header UTF8String], -1, SQLITE_TRANSIENT);
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
PhotoData *data=[[PhotoData alloc]init];
//create the MemoryData object to store the data of one record
//NSLog(@"Data is retrieved using mid=%i",memoryId);
// Read the data from the result row
int pId=sqlite3_column_int(compiledStatement, 1);
NSString *filePath=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
///filePath=[self retrievePath:filePath];
[data setPhotoId:pId];
[data setPhotoPath:filePath];
//Store every object of MemoryData in t
[photoArray addObject:data];
[filePath release];
} // end of the while
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
NSLog(@"size of array is %i",[photoArray count]);
tableArray=[[NSArray alloc]initWithArray:photoArray];
//convert the MutableArray to NSArray
}
,你可以看到,我釋放所有對象,爲什麼出現下列錯誤
2011-12-04 14:48:21.367 Memorable[110:707] Received memory warning. Level=2
2011-12-04 14:48:22.084 Memorable[110:707] Received memory warning. Level=2
2011-12-04 14:48:22.247 Memorable[110:707] Received memory warning. Level=2
2011-12-04 14:48:22.255 Memorable[110:707] Received memory warning. Level=2
2011-12-04 14:48:23.507 Memorable[110:707] Received memory warning. Level=1
2011-12-04 14:48:27.188 Memorable[110:707] Received memory warning. Level=1
Program received signal: 「EXC_BAD_ACCESS」.
warning: Unable to read symbols for /xcode3/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1 (8G4)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).