tags:

views:

138

answers:

1

Hi, so I have a class that I decleare as a singleton and in that class I have a NSMutableArray that contains some NSDictionaries with some key/value pairs in them. The trouble is it doesn't work and I dont't know why... I mean it crashes with EXC_BAD_ACCESS but i don't know where. I followed the code and it did create a new array on first add, made it to the end of the funtion ..and crashed ...

    @interface dataBase : NSObject {
    NSMutableArray *inregistrari;

}

@property (nonatomic,retain) NSMutableArray *inregistrari;



-(void)adaugaInregistrareCuData:(NSDate *)data siValoare:(NSNumber *)suma caVenit:(BOOL)venit cuDetaliu:(NSString *)detaliu;
-(NSDictionary *)raportIntreData:(NSDate *)dataInitiala siData:(NSDate *)dataFinala;
-(NSArray *)luniDisponibileIntreData:(NSDate *)dataInitiala siData:(NSDate *)dataFinala;
-(NSArray *)aniDisponibiliIntreData:(NSDate *)dataInitiala siData:(NSDate *)dataFinala;
-(NSArray *)vectorDateIntreData:(NSDate *)dataI siData:(NSDate *)dataF;
-(void)salveazaInFisier;
-(void)incarcaDinFisier;
+ (dataBase *)shareddataBase;


@end

And here is the .m file

#import "dataBase.h"
#import "SynthesizeSingleton.h"


@implementation dataBase
@synthesize inregistrari;


SYNTHESIZE_SINGLETON_FOR_CLASS(dataBase);


-(void)adaugaInregistrareCuData:(NSDate *)data siValoare:(NSNumber *)suma caVenit:(BOOL)venit cuDetaliu:(NSString *)detaliu{
    NSNumber *v=[NSNumber numberWithBool:venit];
    NSArray *input=[NSArray arrayWithObjects:data,suma,v,detaliu,nil];
    NSArray *keys=[NSArray arrayWithObjects:@"data",@"suma",@"venit",@"detaliu",nil];

    NSDictionary *inreg=[NSDictionary dictionaryWithObjects:input forKeys:keys];

    if(inregistrari == nil) {
        inregistrari=[[NSMutableArray alloc ] initWithObjects:inreg,nil];
    }else {
        [inregistrari addObject:inreg];
    }


    [inreg release];
    [input release];
    [keys release];

}

It made it to the end of that adaugaInregistrareCuData ... ok . said the array had one object ... and then crashed

+2  A: 

Try adding "NSZombieEnabled" with value "YES" to your arguments on your executeable:

Right click your executeable, select get info and add that entry to the variables in the bottom list.

This will tell you what datatype has crashed.

Using build & analyze it tells me that you are releasing inreg, input and keys twice.

All three variables will be autoreleased, your manual release will cause the later autorelease to fail and give you your BAD_ACCESS.

Don't manually release them, remove these three lines from your code:

[inreg release];
[input release];
[keys release];
favo
Current language: auto; currently objective-c(gdb) continue2010-05-22 22:18:59.829 Licenta[2954:207] *** -[CFArray release]: message sent to deallocated instance 0x3b62c70(gdb) This is what I get with the NSZOmbieEnabled ... so it's a CFArray.. wtf is a CFArray ?
Tried whitout the release as you recommended.. still same error.
__forwarding__--forwarding-0nspopautoreleasepooluiapplicationhandleeventpurpleeventcallbackcfrunlooprunspecificcfrunloopruninmodegseventrunmodalgseventrunuiaplicationmainmainyep .. smt to do with the autorelease pool
CFArray is the simple data type NSArrays are based on. Try "Build and analyze" from the menu "Build > Build and analyze". Walk thru the comments it is giving you, it should give you a very good direction where your problems are. When it isn't given you any feedback, do you still have access problems?
favo
Well now I have another problem. the array defined inside the singleton disappears for no reason , and i cant use it in cellForRow atIndexPath .. . nothing is dealocated .. it is used once .. then when the screens moves a little it's just gone