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

  • SEARCH
  • Home
  • 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 7918343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:28:18+00:00 2026-06-03T15:28:18+00:00

I want to use a static class variable to maintain state of a Playlist

  • 0

I want to use a static class variable to maintain state of a Playlist object which will be shared between multiple classes in my app.

I make a call to getPlaylist in my AppDelegate, so that invokes my initialize class method and sets up the MSMutableArray.

However when I invoke addItemToPlaylist, the content variable is no longer the static instance of NSMutableArray. Instead it points to a totally different address in memory- a different address each time I debug.

Am I doing anything obviously wrong? Thanks in advance.

#import "Playlist.h"
static NSMutableArray *content;

@implementation Playlist

+ (void)initialize
{
    content = [NSMutableArray arrayWithCapacity:10]; 
}

+ (NSMutableArray *)getPlaylist
{
    if ([content count] == 0)
        return nil;

    return content;
}  

+ (void)addItemToPlaylist:(PlaylistTrack *)track; 
{
    [content addObject:track];
}
  • 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-06-03T15:28:20+00:00Added an answer on June 3, 2026 at 3:28 pm

    [NSMutableArray arrayWithCapacity] returns an auto-released object (there should be a complaint at runtime about there being no current auto-release pool).

    Use [[NSMutableArray alloc] initWithCapacity] instead and add a class method to release it when done.

    EDIT: Cheers @Lvsti.

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

Sidebar

Related Questions

I have created a public static class utils.cs I want to use it in
I Want to know which one is preferred while coding to use Static Methods
I want something like a static class variable, except when different applications load my
I have a very simple class which I want to use as a subclass
In python, I want to make a class variable static so I can to
I want to use oscpack ( http://code.google.com/p/oscpack/ ) as a static library for my
I have a static front page in Wordpress and I want to use a
I have a public class which has the following method and instance variable: public
I have an application which updates a variable about between 5 to 50 times
in ASP.NET C#., How can i set the variable values of a static class

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.