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:
- Is arrs[] stack- or heap-allocated? And so, would I need to delete it?
- 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.