• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: question about classes, I think
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about classes, I think


  • Subject: Re: question about classes, I think
  • From: "Shawn Erickson" <email@hidden>
  • Date: Thu, 11 May 2006 19:39:49 -0700

On 5/11/06, Alan Smith <email@hidden> wrote:
Okay, sorry about that. It wasn't all that clear and my freind was
probably able to understnad it because he is helping out with this
app, but he's mainly working on th UI.

Here is the code:

#import "EVTable.h"
#import "pluginClass.h"
#import "pluginHelper.h"


@implementation EVTable

- (void)awakeFromNib
{
    tableContents = [[[NSMutableArray alloc] initWithCapacity:3] retain];
}

Why do you retain what you alloc here? When you alloc something it has an implicit retain that you have to balance later on with a release/autorelease (likely in your classes dealloc method). Likely you are over retaining tableContents which will likely leads to a leak.

- (void)appIsDoneLoading
{
    NSLog(@"The files are going to be added to the EV Classic table");

    //Collects the path of the folder that the EV Classic plugins
should be stored in.
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *pluginFolder = [[defaults
dictionaryForKey:@"pathForPluginsStorage"] valueForKey:@"3"];

    NSMutableArray *contents = [[pluginHelper alloc]
pluginsInFolder:pluginFolder forGame:@"0"];

This is a weird bit'o code. What is pluginHelper? It looks like it is a class name since you send it an alloc message. If so it really should start with an upper case letter and some prefix (see [1]). The weird things is after sending it an alloc message you then proceed to send it a pluginsInFolder:forGame message which is a rather strangely named init method IMHO (if that is truly what it is). Maybe you want pluginsInFolder:forGame: to be a class method? Also if the alloc pluginHelper supports is really the normal -[NSObject alloc] you are leaking an instance of pluginHelper (unless pluginsInFolder:forGame: releases it... which would be a bad coding style to follow).

    [contents retain];
    tableContents = contents;
    [contents release];

So you retain contents. Set tableContents to point at what contents points at which losses what tableContents used to point at (the instance you allocated in awakeFromNib). Then you release contents (which is the same thing that tableContents points at). I see no reason for the retain or release here and you likely don't want to do the tableContents assignment as you are (since you are leaking what tableContents used to point at).

    //Updates the table
    [table reloadData];

    NSLog(@"Done putting the files in the EV Classic table");
}

- (void)manageEVPlugins
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *pluginFolder = [[defaults
dictionaryForKey:@"pathForGames"] valueForKey:@"0"];

    //By this time the array I want is empty
    [[pluginHelper alloc] managePlugins:[self contents]
inGamesFolder:pluginFolder];
}

Again this weird alloc of pluginHelper then sending a message other then what one would expect to be an initializer. Again maybe you want managePlugins:inGamesFolder: to be a class method?

Any help will be greatly appreicated.

Don't take this the wrong way but... I think you really need to stop go back and understand Cocoa memory management, object allocation and initialization, difference between objects and pointers, etc. If you don't have the basics down you just going to waste your own time.

<http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/index.html>
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/index.html>

-Shawn

[1] <http://developer.apple.com/documentation/Cocoa/Conceptual/CodingGuidelines/index.html>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: question about classes, I think
      • From: "Alan Smith" <email@hidden>
References: 
 >question about classes, I think (From: "Alan Smith" <email@hidden>)
 >Re: question about classes, I think (From: "Shawn Erickson" <email@hidden>)
 >Re: question about classes, I think (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: Subviews becoming blurry or "chopped up"
  • Next by Date: Re: question about classes, I think
  • Previous by thread: Re: question about classes, I think
  • Next by thread: Re: question about classes, I think
  • Index(es):
    • Date
    • Thread