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 7564251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:51:44+00:00 2026-05-30T13:51:44+00:00

I am trying to do some basic table retrieval from sqlite and I keep

  • 0

I am trying to do some basic table retrieval from sqlite and I keep stumbling over some memory leak I cannot figure out, especially since it appears only with one of two equivalent lines.

What I do is simple :

-Create an object (category) to hold my sqlite DB line

-Have a method that queries sqlite and returns an array of these objetcs

I put all the code here (stripped it down a bit to simplify but the I have the memory leak with this very code).

category.h:

@interface Category : NSObject {
    int         catId;
    NSString    *description;
    int         order;
    NSString    *iconName;
}

@property(nonatomic, readwrite, assign) int catId;
@property(nonatomic, retain) NSString *description;
@property(nonatomic, readwrite, assign) int order;
@property(nonatomic, retain) NSString *iconName;


@end

category.m:

#import "Category.h"


@implementation Category

@synthesize catId;
@synthesize description;
@synthesize order;
@synthesize iconName;

@end

Method to retrieve array:

-(NSMutableArray *)getAll {

    NSString *query = "select id, description, catorder, image from category order by catorder";
    sqlite3_stmt    *statement;
    NSMutableArray  *categoryArray = [[NSMutableArray alloc] init];

    if (sqlite3_prepare_v2([[Database sharedDatabase] instance], [query UTF8String], -1, &statement, nil) == SQLITE_OK) {
        while (sqlite3_step(statement) == SQLITE_ROW) {
            int     dbId =              sqlite3_column_int(statement, 0);
            char    *dbDescription =    (char *)sqlite3_column_text(statement, 1);
            int     dbOrder =           sqlite3_column_int(statement, 2);
            char    *dbIcon =           (char *)sqlite3_column_text(statement, 3);

            NSString *desc = [[NSString alloc] initWithUTF8String:dbDescription];
            NSString *icon = [[NSString alloc] initWithUTF8String:dbIcon];          

            Category *category = [[Category alloc] init];

            category.catId=dbId;
            category.description = desc;
            //category.description = @"Test";
            category.order = dbOrder;
            category.iconName = icon;
            //category.icon = @"test.png";

            [desc release];         
            [icon release];

            [categoryArray addObject:category];

            [category release];
        }
        sqlite3_finalize(statement);
    }
    [categoryArray autorelease];
    return categoryArray;
}

This line leaks

NSString *icon = [[NSString alloc] initWithUTF8String:dbIcon];          

This line doesn’t

NSString *desc = [[NSString alloc] initWithUTF8String:dbDescription];

Here what instruments shows :
enter image description here

and when I drill down :
enter image description here

  • 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-30T13:51:45+00:00Added an answer on May 30, 2026 at 1:51 pm

    You don’t have a dealloc method. You need to have this in your Category.m file:

    -(void)dealloc
    {
        [description release];
        [iconName release];
        [super dealloc];
    }
    

    Also, I’m pretty sure you can’t have a property named “description”. That’s a reserved method name.

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

Sidebar

Related Questions

I'm trying to implement some basic linear algebra operations and one of these operations
I'm trying to do some basic paging in MSSQL. The problem I'm having is
I am trying to some pretty basic RMI: // Context namingContext = new InitialContext();
I am using VS 2010 RTM and trying to perform some basic validation on
Im trying to get into some basic JavaFX game development and I'm getting confused
I'm trying to do some very basic time math - basically, given inputs of
I am trying to get my head round some basic erlang functionality and I
What I'm trying to do with MRS is to teach myself some basic AI;
I am trying to build an application to simulate some basic spheres moving around.
I'm trying to implement the WMD editor used on StackOverflow to create some basic

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.