×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    30

    Arrow Does this leak memory?

    Code:
    for(int i=0; i<10000; i++)  {
    
        // i am neither calling Prepare nor close() on the stmt so ideally it should not hold any open resources right?  
        RSqlStatement stmt; 
    
    }

    Actually, following code snippet is exactly what I am doing in my code, iStmt1, iStmt2, iStmt3 are member variables of the class and are Prepared and kept but stmt0 is not prepared and it is not being closed so I am a little worried whether it will cause any leaks or unclosed resources, as you can see from the code I have no way of closing stmt0 because after the stmt = iStmt1 assignment stmt0 became iStmt1

    Code:
    for( <lot of times>)  {
     
    RSqlStatement stmt0;
    RSqlStatement &stmt = stmt0;
    
    if( ) {
    
    stmt = iStmt1;
    
    } else if (){
    
    stmt = iStmt2;
    
    } else if() {
    
    stmt = iStmt3;
    
    }
    
    
    stmt.Next(); // gets the data 
    
    }

    May be I am being a little paranoid here but it is always better to ask, can anyone please answer this question, thanks.
    Last edited by budugu; 2010-10-02 at 19:45.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Does this leak memory?

    In short: yes, stmt0 is a leak. The rule of thumb is that R-objects opened by you also have to be closed by you. Otherwise memory / other kind of resources may get leaked (there is a fistful of R-classes which actually do not require closing, but database-related stuff can hardly belong to this group).

    A C++ thing is that references can not be re-assigned, so the end of
    Code:
    RSqlStatement stmt0;
    RSqlStatement &stmt = stmt0;
    stmt = iStmt1;
    is actually an stmt0=iStmt1 operation, which is not necessarily safe.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    30

    Re: Does this leak memory?

    Quote Originally Posted by wizard_hu_ View Post
    The rule of thumb is that R-objects opened by you also have to be closed by you. Otherwise memory / other kind of resources may get leaked (there is a fistful of R-classes which actually do not require closing, but database-related stuff can hardly belong to this group).
    I didn't call Prepare on the RSqlStatement stmt in the first example, even then there will be a leak?

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Does this leak memory?

    No, since that is a simple uninitialized local variable then.

Similar Threads

  1. Need Help: Memory Leak
    By max_gudluck in forum Symbian
    Replies: 2
    Last Post: 2008-12-21, 07:41
  2. memory leak
    By Digish in forum Symbian
    Replies: 2
    Last Post: 2008-04-07, 06:46
  3. memory leak
    By sandy_zeng in forum Symbian
    Replies: 5
    Last Post: 2007-08-08, 09:46
  4. memory leak on emulator = memory leak on device
    By manmli in forum Mobile Java General
    Replies: 2
    Last Post: 2006-08-05, 19:54
  5. memory leak
    By kunal_the_one in forum Symbian
    Replies: 0
    Last Post: 2004-09-15, 08:12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×