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:
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.
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.
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.