Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4570506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:22:17+00:00 2026-05-21T19:22:17+00:00

I have a shopping cart in my app. I also have a UIBarButton called

  • 0

I have a shopping cart in my app. I also have a UIBarButton called “Empty Cart”. Im implementing functionality for this button. However, Im running into some problems. My Cart is a Singleton Data Object. What I want to do is when the user presses “Empty Cart”, all the objects and variable values in the cart should be released and/or made 0.

I have an “emptyCart” method implemented in my ViewController which calles an “emptyCart” method of the CartSingleton in turn. My problem is as shown below the release calls to the various objects are not releasing the objects, because when I print the contents of the Cart after running “empty cart”, i can still see all the items in the Cart. Does the release message not take effect right away? How can I instantly release all the objects in my Cart then?

Code- “Empty Cart” in Singleton:

-(void)emptyCart

{

if (self.selectedLocation != NULL)
   {
    [self.selectedLocation release];
    self.locationSelected = false;
   }

if (self.foodItemsArray != NULL)
   {
    for (int i = 0; i < [self.foodItemsArray count]; i++)
       {
        FoodItem *temp = [self.foodItemsArray objectAtIndex:i];
        if (temp.sidesArray != NULL)
           {
            [temp.sidesArray release];
           }
       }
[self.foodItemsArray release];  
   }

if (self.drinkItemsArray != NULL)
   {
    [self.drinkItemsArray release];
   }

if (self.otherItemsArray != NULL)
   {
    [self.otherItemsArray release];
   }

if (self.customerInfo != NULL)
   {
    [self.customerInfo release];
   }

self.numFoodItems = 0;
//self.totalTaxPercent = 0;
self.foodItemsTotalCost = 0;
self.drinkItemsTotalCost = 0;
self.otherItemTotalCost = 0;
self.totalCostOfAllItems = 0;
self.totalTaxesAmount = 0;
self.totalChargesWithTaxes = 0;
self.gratuity = 0;
self.miscCharges = 0;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:22:18+00:00Added an answer on May 21, 2026 at 7:22 pm

    Releasing releases right away — meaning, it reduces the retain count, and if the retain count is 0, then the object is deallocated.

    Your problem is that you are holding onto the objects — not setting the variables to nil after you are done with them.

    I am also worried that you are releasing too many times

    1. Arrays release their elements when they are released
    2. retained @properties will release the object they are set to if you set them to nil – you should be clearing them like so:

      self.customerInfo = nil;

    So, watch out. It looks like right now you are accessing released objects — which will crash eventually. Over releasing will also cause problems.

    To try to find out these issues

    1. Use Build and Analyze and fix the errors it reports
    2. Turn on Zombies and see if you are accessing released objects

      http://www.loufranco.com/blog/files/debugging-memory-iphone.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i'm creating an app which have shopping cart and payment done via paypal
I'm making a shopping cart app in Google App Engine. I have many classes
I have a rails app (rails 3.1.3) that has a shopping cart model. I
I have a shopping cart. I also have a partial view cartSummary - it
I have a shopping cart system in Cakephp, this table has all your usual
I have shopping cart web application. when I am running that in my local
I have a shopping cart page (Cart.aspx) that has a button that will (sometimes)
I have a shopping cart flow like this: Page 1 . Choose Products Page
I have a shopping cart in my app and an underlying data structure that
I have a shopping cart in my iPhone app. Once the user is done

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.