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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:35:32+00:00 2026-05-27T09:35:32+00:00

In the following code snippet, I am leaking 52 bytes of memory for every

  • 0

In the following code snippet, I am leaking 52 bytes of memory for every iteration of the for loop, but after several hours I am unable to determine why =/

Any help will be appreciated.

    for(unsigned char i=0; i<128; ++i)
    {
        ttf.loadGlyph(i);
        FT_Glyph glyph;
        FT_Get_Glyph(ttf.ftFace_->glyph, &glyph);
        FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
        FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
        FT_Bitmap& bitmap = bitmap_glyph->bitmap;

        int width = nextPowerOf2(bitmap.width);
        int height = nextPowerOf2(bitmap.rows);
        GLubyte* expanded_data = new GLubyte[ 2 * width * height]; // Allocate Memory For The Texture Data.

        for(int j=0; j <height;j++) {
            for(int i=0; i < width; i++){
                expanded_data[2*(i+j*width)]= expanded_data[2*(i+j*width)+1] =
                    (i>=bitmap.width || j>=bitmap.rows) ?
                    0 : bitmap.buffer[i + bitmap.width*j];
            }
        }
        glBindTexture( GL_TEXTURE_2D, fontData_.pTextures_[i]);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data );

        delete [] expanded_data;

        glNewList(fontData_.fontBase_+i, GL_COMPILE);
        glBindTexture(GL_TEXTURE_2D, fontData_.pTextures_[i]);
        glPushMatrix();
        glTranslatef( (GLfloat)bitmap_glyph->left, 0.0f, 0.0f );
        glTranslatef(0.0f, (GLfloat)bitmap_glyph->top-bitmap.rows, 0.0f);

        float   x=(float)bitmap.width / (float)width,
            y=(float)bitmap.rows / (float)height;

        glBegin(GL_QUADS);

        glTexCoord2d(0,0); glVertex3f( 0, 0, 1 );                       //Bottom-left vertex (corner) 
        glTexCoord2d(0,y); glVertex3f( 0, (GLfloat)bitmap.rows, 1 );    // top left vertex
        glTexCoord2d(x,y); glVertex3f( (GLfloat)bitmap.width, (GLfloat)bitmap.rows, 1 ); // top right vertex
        glTexCoord2d(x,0); glVertex3f( (GLfloat)bitmap.width, 0, 1 );   // bottom right

        glEnd();
        glPopMatrix();
        glTranslatef( (GLfloat)( ttf.ftFace_->glyph->advance.x >> 6 ), 0, 0);
        glEndList();
    }
  • 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-27T09:35:33+00:00Added an answer on May 27, 2026 at 9:35 am

    From the docs:

    FT_Get_Glyph

    A function used to extract a glyph image from a slot. Note that the
    created FT_Glyph object must be released with FT_Done_Glyph.

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

Sidebar

Related Questions

Instruments is informing me that I am leaking memory from the following code snippet
The following code snippet illustrates a memory leak when opening XPS files. If you
This following code snippet works fine using jQuery1.2.3, but it doesn’t work with latest
The following code snippet works fine in 1.8.7 on Mac OS X, but not
The following code snippet has a memory leak that I spent too much time
The following code snippet works in FF but not on IE8. Prev is returning
The following code snippet is causing a compilation error that I am unable to
The following code snippet compiles just fine on Mac OS X with gcc, but
The following code snippet on SQL server 2005 fails on the ampersand '&': select
The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk

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.