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

  • Home
  • SEARCH
  • 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 1065329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:47:16+00:00 2026-05-16T19:47:16+00:00

I have a few arrays and a resource that needs deletion, the value of

  • 0

I have a few arrays and a resource that needs deletion, the value of these variables are retained throughout the lifetime of the program and they are only used in a single function so it naturally fits into static variables:

void func() {
    static GLfloat arrs[4] = {1, 1, 1, 1};
    static GLUquadric* quad = gluNewQuadric(); // delete with gluDeleteQuadric(quad)
    //... other codes ... 
}

However, if I used static, I would have trouble with delete-ing these resources since I cannot access these variables from outside the function. I can make these globals, but I would like to avoid that if possible.

So the question is:

  1. Is arrs[] stack- or heap-allocated? And so, would I need to delete it?
  2. In the case of GLUquadric, obviously the compiler would not know how to properly delete it, for now I’ve used a RAII wrapper class which worked beautifully, but I’m looking if there’s an even simpler approach.

valgrind complained for not releasing the GLUquadric, and I guess I’d just clean it up rather than silencing valgrind even though the program should be about to end anyway when I will release them and these resources are probably(?) released when the program ends.

  • 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-16T19:47:16+00:00Added an answer on May 16, 2026 at 7:47 pm
    1. No need to delete arrs[], it’s not been allocated on the heap. It is not on the stack either, it’s in the data segment somewhere, and part of your static program data and will go away when the process does.

    2. On the heap but generally not to worry about. This sort of allocating heap during static initialisation is not very good, but it only bytes you if you need any destructor calls in the end (to get rid of external resources etc.).

    Edited: I’d still worry about that heap object. especially if it comes from some library; you never know what it is up to internally, it may have locked up some hardware resources or similar. You can’t do anything here with smart pointers etc., but if you really need this to be allocated this way, it may be worth registering the deallocation with the atexit() function or similar. Or put the whole thing into a global static singleton object with a destructor. You only have nothing to worry about if you know that the object only contains data, i.e. don’t worry about your heap.

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

Sidebar

Related Questions

I have a few arrays that I want to send to process with PHP.
I have few arrays of ccspirit images, these are balloons of different colors, like
I have a class that contains a few multi-dimensional arrays. I am trying to
I have a javascript object that contains a few objects that contain associative arrays.
I have a few html image tags that fill an array. On the page
I have populated an array with a few html image tags that I have
I have a few arrays of the same length. I want to sort the
I have two numpy arrays that are OpenCV convex hulls and I want to
I have few inline sql statements with some arrays and if loops. I want
I have a simple JavaScript Array object containing a few numbers. [267, 306, 108]

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.