I am using XML parser to get my data.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ( [elementName isEqualToString:#"country"] )
{
x++;
[messages addObject:[NSDictionary dictionaryWithObjectsAndKeys:Id,#"ID",Name,#"NAME",Image,#"IMAGE",nil]];
//**111**
NSLog(#"Data in Message : %#", [messages objectAtIndex:(x-1)]);
[Id setString:#""];
[Name setString:#""];
[Image setString:#""];
}
if ( [elementName isEqualToString:#"id"] )
{
[Id appendString:currentNodeContent];
}
if ( [elementName isEqualToString:#"name"] )
{
[Name appendString:currentNodeContent];
}
if ( [elementName isEqualToString:#"im"] )
{
[Image appendString:currentNodeContent];
}
}
//At //*111* the message is printed but when I do this after calling the xml parser, it doesn't print:
chatParser = [[NSXMLParser alloc] initWithData:receivedData];
[chatParser setDelegate:self];
[chatParser parse];
NSLog(#"\n\nMessages...\n\n%#", messages); //here there is no data printing
at this point it is printing empty..
Messages.
(
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
)
I have define message properties and also sythesize it.
In viewDidLoad I have did this
messages=[[NSMutableArray alloc] init];
Thank you for help..
Your problem is that you use same objects Id, Name, Image all the time and with the lines
[Id setString:#""];
[Name setString:#""];
[Image setString:#""];
set their values to "" at the end of each country element.
It better should look like this (not tested, maybe some typos):
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"id"] )
{
[lastMessage setObject:currentNodeContent forKey:"ID"];
}
else if ( [elementName isEqualToString:#"name"] )
{
[lastMessage setObject:currentNodeContent forKey:"NAME"];
}
else if ( [elementName isEqualToString:#"im"] )
{
[lastMessage setObject:currentNodeContent forKey:"IMAGE"];
}
else if ( [elementName isEqualToString:#"country"] )
{
NSLog(#"Data in Message : %#", lastObject);
[messages addObject:lastMessage];
[lastMessage release];
}
}
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elName namespaceURI:(NSString *)uri
{
if ( [elementName isEqualToString:#"country"] )
{
lastMessage = [[NSMutableDictionary alloc]init];
}
}
Use the Below Code.Where Table is NSObject Class with the CaseId,PartyId,CartId as a properties in this class.If you have the xml url just called loadXMLByURL method with URl.After parsing you will get Each Object in TableArray which have the Table object with above properties.
NSMutableString *currentNodeContent;
NSXMLParser *parser;
Tweet *currentTweet;
bool isStatus;
-(id) loadXMLByURL:(NSString *)urlString
{
_tweets = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:#"Table"])
{
currentTable = [Table alloc];
isStatus = YES;
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (isStatus)
{
if ([elementname isEqualToString:#"CaseId"])
{
currentTable.CaseId = currentNodeContent;
}
if ([elementname isEqualToString:#"PartyId"])
{
currentTable.PartyId = currentNodeContent;
}
if ([elementname isEqualToString:#"CartId"])
{
currentTable.CartId = currentNodeContent;
}
}
if ([elementname isEqualToString:#"Table"])
{
[self.tableArray addObject:currentTable];
currentTable = nil;
currentNodeContent = nil;
}
}
Let me know if you have any doubt.
Related
I parse a xml file to get the content of two nodes "tagid" and "mac".
How can I store this content in two arrays, one for "tagid" and one for "mac"?
The "parser" works. Thank you in advance
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
self.currentElement = elementName;
self.currentElement2 = elementName;
if ([self.currentElement isEqualToString:#"mac"]) {
self.currentTitle = [NSMutableString string];
}
if ([self.currentElement2 isEqualToString:#"tagid"]) {
self.currentTitle2 = [NSMutableString string];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([self.currentElement isEqualToString:#"mac"]) {
NSLog(#"%#", self.currentTitle);
}
if ([self.currentElement2 isEqualToString:#"tagid"]) {
NSLog(#"%#", self.currentTitle2);
}
self.currentTitle = nil;
self.currentElement = nil;
self.currentTitle2 = nil;
self.currentElement2 = nil;
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (!self.currentElement) return;
if ([self.currentElement isEqualToString:#"mac"]) {
self.currentTitle = string;
}
if (!self.currentElement2) return;
if ([self.currentElement2 isEqualToString:#"tagid"]) {
self.currentTitle2 = string;
}
}
- (IBAction)aktualisieren:(id)sender {
NSURL *xmlURL = [[NSURL alloc] initWithString:#"http://mysite/mycontent"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[parser setDelegate:self];
[parser parse];
}
Thank you for your responses :)
create two arrays in parseStartDocument. one for mac-MacArray , one for tagid-tagArray.
in didEndElement method,check for element & add your self.currentTitle to that perticular your Array.
In .h declare two arrays tagArray and macArray.
In viewDidLoad alloc init both arrays.
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([self.currentElement isEqualToString:#"mac"]) {
[macArray addObject:self.currentTitle];
NSLog(#"%#", self.currentTitle);
}
if ([self.currentElement2 isEqualToString:#"tagid"]) {
[macArray addObject:self.currentTitle2];
NSLog(#"%#", self.currentTitle2);
}
self.currentTitle = nil;
self.currentElement = nil;
self.currentTitle2 = nil;
self.currentElement2 = nil;
}
You need two different arrays
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
self.currentElement = elementName;
self.currentElement2 = elementName;
if ([self.currentElement isEqualToString:#"mac"]) {
self.currentTitle = [NSMutableString string];
NSMutableArray *macArray = [NSMutableArray alloc] init];
}
if ([self.currentElement2 isEqualToString:#"tagid"]) {
self.currentTitle2 = [NSMutableString string];
NSMutableArray *tagIdArray = [NSMutableArray alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([self.currentElement isEqualToString:#"mac"]) {
NSLog(#"%#", self.currentTitle);
[macArray addObject:self.currentTitle];
}
if ([self.currentElement2 isEqualToString:#"tagid"]) {
NSLog(#"%#", self.currentTitle2);
[tagIdArray addObject:self.currentTitle2];
}
self.currentTitle = nil;
self.currentElement = nil;
self.currentTitle2 = nil;
self.currentElement2 = nil;
}
Declare two mutable arrays:
NSMutableArray *macArray , *tagidArray;
macArray = [[NSMutableArray alloc]init];
tagidArray = [[NSMutableArray alloc]init];
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([self.currentElement isEqualToString:#"mac"]) {
[macArray addObject:self.currentTitle];
NSLog(#"%#", self.currentTitle);
}
if ([self.currentElement2 isEqualToString:#"tagid"]) {
[tagidArray addObject:self.currentTitle2];
NSLog(#"%#", self.currentTitle2);
}
}
-(void)parserDidEndDocument{
//Do something as parsing has been completed here and your values are in two arrays
}
Find detailed parsing example here
By the way, if either of these was a long string, might get separated into multiple calls to foundCharacters. Thus, foundCharacters should always append strings, not setting strings:
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (!self.currentElement) return;
if ([self.currentElement isEqualToString:#"mac"]) {
[self.currentTitle appendString:string];
}
if (!self.currentElement2) return;
if ([self.currentElement2 isEqualToString:#"tagid"]) {
[self.currentTitle2 appendString:string];
}
}
<NewDataSet>
<Table>
<CaseId>743</CaseId>
<PartyId>11100550</PartyId>
<CartId>18</CartId>
</Table>
<Table>
<CaseId>742</CaseId>
<PartyId>11100549</PartyId>
<CartId>1148</CartId>
<BusinessID>19</BusinessID>
</Table>
</NewDataSet>
NSData* data = [xmlResponseData dataUsingEncoding:NSUTF8StringEncoding];
// NSXMLParser *XMLparser = [[NSXMLParser alloc] initWithData:data];
// [XMLparser setDelegate:self];
BOOL success;
if (XMLparser) // addressParser is an NSXMLParser instance variable
[XMLparser release];
XMLparser = [[NSXMLParser alloc] initWithData:data];
[XMLparser setDelegate:self];
[XMLparser setShouldResolveExternalEntities:YES];
success = [XMLparser parse]; // return value not used
// if not successful, delegate is informed of error
if(success)
NSLog(#"Sucess Parsed");
else
NSLog(#"Error Error Error!!!");
// NSLog(#"Parsed string : %#",valueForItem);
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:#"NewDataSet"]) {
caseID_List = [[NSMutableArray alloc]init];
}
NSLog(#"Processing Element: %#", elementName);
if ([elementName isEqualToString:#"CaseId"]) {
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(#"Processing Value: %#", currentElementValue);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:#"NewDataSet"])
return;
}
I need only CaseId to store from the given xml. Can any one advice me on this simple parsing!
For me its looping! and getting all details
Use the Below Code.Where Table is NSObject Class with the CaseId,PartyId,CartId as a properties in this class.If you have the xml url just called loadXMLByURL method with URl.After parsing you will get Each Object in TableArray which have the Table object with above properties.
NSMutableString *currentNodeContent;
NSXMLParser *parser;
Tweet *currentTweet;
bool isStatus;
-(id) loadXMLByURL:(NSString *)urlString
{
_tweets = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:#"Table"])
{
currentTable = [Table alloc];
isStatus = YES;
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (isStatus)
{
if ([elementname isEqualToString:#"CaseId"])
{
currentTable.CaseId = currentNodeContent;
}
if ([elementname isEqualToString:#"PartyId"])
{
currentTable.PartyId = currentNodeContent;
}
if ([elementname isEqualToString:#"CartId"])
{
currentTable.CartId = currentNodeContent;
}
}
if ([elementname isEqualToString:#"Table"])
{
[self.tableArray addObject:currentTable];
currentTable = nil;
currentNodeContent = nil;
}
}
Let me know if you have any doubt.
I have a xml file with this:
<name>Alberto</name>
<subname>Martín</subname>
<age>24</age>
I want parser it with NSXMLParser and save data it in:
NSString *name;
NSString *subname;
NSString *age;
To do it im using:
-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *)
elementName namespaceURI (NSString *) namespaceURI
qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict {
if( [elementName isEqualToString:#"name"])
{
if (!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
elementoEncontrado = YES;
}}
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string{
if (elementoEncontrado)
{
[soapResults appendString: string];
}
}
-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"name"])
{
name=soapResults;
}
if ([elementName isEqualToString:#"subname"])
{
subname=soapResults;
}
if ([elementName isEqualToString:#"age"])
{
age=soapResults;
}
NSLog(#"%#", name, subname, age);
The problem is that subname and age never appears...
You should check for all elements here, since you're only creating the NSMutableString for name elements.
-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *)
elementName namespaceURI (NSString *) namespaceURI
qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict {
if( [elementName isEqualToString:#"name"])
{
if (!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
elementoEncontrado = YES;
}
}
and release / nil your soapResults here, as well as set your elementoEncontrado to NO here
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"name"])
{
// copy or retain this, unless ARC.
name=soapResults;
}
if ([elementName isEqualToString:#"subname"])
{
subname=soapResults;
}
if ([elementName isEqualToString:#"age"])
{
age=soapResults;
}
NSLog(#"%#", name, subname, age);
[soapResults release];
soapResults = nil;
elementoEncontrado = NO;
}
I am Parsing Web urls from server and storing them in Strings and then displaying it on Webview. But now when i am parsing Spanish words like
http://litofinter.es.milfoil.arvixe.com/litofinter/PDF/Presentación_LITOFINTER_(ES).pdf
it is accepting it
PDF File Name ++++++ http://litofinter.es.milfoil.arvixe.com/litofinter/PDF/Presentaci
PDF File Name ++++++ ón_LITOFINTER_(ES).pdf
i.e two different strings... i know i have to make small change that is append the string but i am not able to do it now, can anyone help me out. Here is my code :-
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElement = elementName;
if([currentElement isEqualToString:#"category"]) {
NSLog(#"Current element in Category:- %#",currentElement);
obj = [[Litofinter alloc]init];
obj.productsArray = [[NSMutableArray alloc]init];
}
if([currentElement isEqualToString:#"Product"]) {
obj.oneObj = [[Products alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if([currentElement isEqualToString:#"Logo"]) {
obj.cLogo=[NSString stringWithFormat:#"%#",string];
NSLog(#"Logo to be saved in Array :- %#",obj.cLogo);
}
if([currentElement isEqualToString:#"Name"]) {
obj.cName=[NSString stringWithFormat:#"%#",string];
NSLog(#"Name to be saved in Array :- %#",string);
}
if([currentElement isEqualToString:#"cid"]) {
obj.cId=(int)[NSString stringWithFormat:#"%#",string];
NSLog(#"CID to be saved in Array :- %#",string);
}
if([currentElement isEqualToString:#"pid"]) {
//obj.oneObj.id = (int)[NSString stringWithFormat:#"%#",oneBook.id];
obj.oneObj.id = (int)[oneBook.id intValue];
}
if([currentElement isEqualToString:#"Title"]) {
obj.oneObj.title = [NSString stringWithFormat:#"%#",string];
}
if([currentElement isEqualToString:#"Thumbnail"]) {
obj.oneObj.thumbnail= [NSString stringWithFormat:#"%#",string];
}
// problem occuriing while parsing Spanish characters...
if([currentElement isEqualToString:#"pdf"]) {
obj.oneObj.pdf = [NSString stringWithFormat:#"%#",string];
NSLog(#"PDF File Name ++++++ %#",string);
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:#"category"]) {
NSLog(#"Current element in End Element Category:- %#",currentElement);
[TableMutableArray addObject:obj];
}
if([elementName isEqualToString:#"Product"]) {
[obj.productsArray addObject:obj.oneObj];
}
currentElement = #"";
}
I will be thankful to you.
I found the answer :
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElement = elementName;
// MOdified
else if([currentElement isEqualToString:#"pdf"]) {
// obj.oneObj.pdf = [NSString stringWithFormat:#"%#",string];
// NSLog(#"PDF File Name ++++++ %#",string);
NSMutableString *outputBuilder = [[NSMutableString alloc]init] ;
[outputBuilder appendString:[NSString stringWithFormat:#"%#", self.pdfString]];
[outputBuilder appendString:[NSString stringWithFormat:#"%#", string]];
self.pdfString = outputBuilder;
[outputBuilder release];
}
else
{
self.pdfString = string;
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([currentElement isEqualToString:#"pdf"])
{
obj.oneObj.pdf = self.pdfString;
NSLog(#"PDF File Name ++++++ %#",obj.oneObj.pdf);
}
currentElement = #"";
}
and a small change also that is where i am passing this use this:-
NSString *urlString = [appDelegate.currentBookPressed stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
declare NSString in .h file;
in Did Start parse
str=#"";
if([currentElement isEqualToString:#"pdf"]) {
str=[str stringByAppendingString:string];
obj.oneObj.pdf = [NSString stringWithFormat:#"%#",str];
NSLog(#"PDF File Name ++++++ %#",str);
}
I've been trying for some time now to get xml parser working leak free and efficient but so far unsuccessful. I've removed additional fields as they are all the same.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [[elementName copy] autorelease];
if ([elementName isEqualToString:#"source"]) {
if (!currentID) {
overlays = [[NSMutableArray alloc] init];
currentID = [[NSMutableString alloc] init];
} else {
[currentID release];
currentID = nil;
currentID = [[NSMutableString alloc] init];
}
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"source"]) {
overlay = [[NSMutableDictionary alloc] init];
[overlay setObject:currentID forKey:#"id"];
[overlays insertObject:overlay atIndex:[overlays count]];
[overlay release];
overlay = nil;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
string = [string stringByReplacingOccurrencesOfString:#"\n" withString:#""];
string = [string stringByReplacingOccurrencesOfString:#"\t" withString:#""];
if ([currentElement isEqualToString:#"id"]) {
[self.currentID appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[currentID release];
currentID = nil;
//[self addResources];
}
Any help would be appreciated.
If you have declared properties for your ivars I would recommend to use them. This makes memory management easier. This is how I would write your code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
self.currentElement = elementName;
if ([elementName isEqualToString:#"source"]) {
if (!self.currentID) {
self.overlays = [NSMutableArray array];
self.currentID = [NSMutableString string];
} else {
self.currentID = [NSMutableString string];
}
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"source"]) {
[self.overlays addObject:
[NSDictionary dictionaryWithObjectsAndKeys:self.currentID,#"id",nil]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
string = [string stringByReplacingOccurrencesOfString:#"\n" withString:#""];
string = [string stringByReplacingOccurrencesOfString:#"\t" withString:#""];
if ([self.currentElement isEqualToString:#"id"]) {
[self.currentID appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
self.currentID = nil;
}
You might also want to try Build&Analyse for your code. this may point out where you are leaking.