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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:03:28+00:00 2026-06-07T13:03:28+00:00

Do I have a memory leak? I am building a game engine and I

  • 0

Do I have a memory leak?
I am building a game engine and I have some code that I think is right but my code analysis tools ( cppcheck ) says I have memory leak, it maybe a false positive.

I have a ( this is a bare bones use case )

class Mesh
{
D3DMATERIAL9* mpMaterials;
LPDIRECT3DTEXTURE9* mpTextures;

D3DMATERIAL9*& GetMaterials() { return mpMaterials; }
LPDIRECT3DTEXTURE9*& GetTexures() {return mpTextures; }
};

in my mesh class I have some directx pointers
When I load the mesh I send a shared_ptr to a function in my graphics manager class to be loaded.

In that function I do

void Renderer::LoadMesh( shared_ptr<Mesh> myMesh)
{
// other code
D3DMATERIAL9*& pMaterials= myMesh->GetMaterials();
LPDIRECT3DTEXTURE9*& pTextures= myMesh->GetTextures();
// other code

// and then instantiate them

pMaterials = new D3DMATERIAL9[matCount];
pTextures = new LPDIRECT3DTEXTURE9[texCount];

// And then i do some stuff with those objects.
}

Now at the end of this function is when cpp check says pMaterials and pTextures leaked their memory. It is my understanding that pMaterials and pTextures are references to the pointers within myMesh and that the memory I instantiated lives there because the pointers in the Mesh class point to that instantiated memory, and that as long as I destroy the Mesh object properly sometime later ( and call delete[] mpMaterials; delete[] mpTextures; in the Mesh destructor ) I have not leaked memory right?

  • 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-07T13:03:30+00:00Added an answer on June 7, 2026 at 1:03 pm

    I wrote the memory leaks check in cppcheck. and I agree that is a false positive. I will fix it.

    feel free to report it in the cppcheck issue tracker.

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

Sidebar

Related Questions

I have some PL/SQL code that I think might have a memory leak. Everytime
I believe I have memory leak with some of my code that uses the
I think that I have a memory leak in my app witch I can't
I have a problem with a memory leak. I have this code in a
I have successfully debugged my own memory leak problems. However, I have noticed some
Our team is faced with slow but serious Javascript memory leak . We have
I have memory leak in the web application (servlet) that I am working on.
I have a memory leak with below code. If I use [sub release]; after
I have a memory leak problem that just can not understand! Watch this initialization
I have an .net app that seems to have a memory leak issue(s). The

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.