Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-27-2011, 04:48 AM   #1 (permalink)
Registered Member
 
manojb's Avatar
 
Join Date: Jan 2011
Posts: 263
manojb is on a distinguished road
Default Pointer not released !

hey guys,

Here in my code, i add sections to a tableview from webservice. for every section, i have an item array whose values are also obtained from the webservice. now the problem is if i have 2 sections, the item array first loads the items to the first section, then on fetching the items of second section, it again loads the items to the first section.... I can detect that the pointer reference to both are same.

Code:
if (dataOption == kLoadItems) {

            ItemSection *itemSection = [[IitemSection alloc] init];
            if (itemSection != nil) {
                itemSection = nil; [itemSection release];
            }
            itemSection = [itemController.itemSectionList objectAtIndex:_selectedSectionIndex];
            itemSection.itemList = (NSMutableArray*)[data dataObject];
        }
[_tableView reloadData];
the dataObject brings the items array from the webservice and it does contain valid data.

Kindly help me how i could load the items in the two sections...
__________________
U can not fail, until U Quit...

Manoj B

Last edited by manojb; 05-27-2011 at 11:26 AM.
manojb is offline   Reply With Quote
Old 05-27-2011, 05:48 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

i dont' understand why you are allocing and then release the line below.

However you would have 1 array of objects for each sections,

If i understand what you mean, you have
Code:
itemSection = [itemController.itemSectionList objectAtIndex:_selectedSectionIndex];
where you are using this array itemController.itemSectionList for both sections....so as said, you need to have 2 different array...so that you can use the right array depending on indexPath.section
__________________
dany_dev is offline   Reply With Quote
Old 05-27-2011, 10:59 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by manojb View Post
Code:
            ItemSection *itemSection = [[IitemSection alloc] init];
            if (itemSection != nil) {
                itemSection = nil; [itemSection release];
            }
            itemSection = [itemController.itemSectionList objectAtIndex:_selectedSectionIndex];
            itemSection.itemList = (NSMutableArray*)[data dataObject];
Like dany_dev said, that alloc and release doesn't make sense. Here is what actually happens when you do that. A new ItemSection is allocated and itemSection is made to point at it. Since it is probably not nil, it goes into the next block of code. There you first set itemSection to nil. This immediately creates a leak, because now the ItemSection that was just allocated now has nothing pointing to it, so there is no way to ever release it. The you "try" to release it. But you are trying to release it through a pointer that is already set to nil, so it does nothing. (release is designed to do nothing when applied to nil, so it is not an error.) Next, you are outside the "if" block and you now assign itemSection to something in an array, which may or may not be an error - depending on what is in that array. But the only effect of your "if" block was to produce a leak. If you had just done the release before making the pointer nil, then there would be no leak.
RLScott is offline   Reply With Quote
Old 05-27-2011, 11:28 AM   #4 (permalink)
Registered Member
 
manojb's Avatar
 
Join Date: Jan 2011
Posts: 263
manojb is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
i dont' understand why you are allocing and then release the line below.

However you would have 1 array of objects for each sections,

If i understand what you mean, you have
Code:
itemSection = [itemController.itemSectionList objectAtIndex:_selectedSectionIndex];
where you are using this array itemController.itemSectionList for both sections....so as said, you need to have 2 different array...so that you can use the right array depending on indexPath.section
Thanks dany, that was an attempt to release the pointer reference in my sections array. I coded originally like,
Code:
if (dataOption == kLoadItems) {
            itemSection = [itemController.itemSectionList objectAtIndex:_selectedSectionIndex];
            itemSection.itemList = (NSMutableArray*)[data dataObject];
        }
[_tableView reloadData];
__________________
U can not fail, until U Quit...

Manoj B
manojb is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 336
6 members and 330 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0