Kiosk GUI Screens

I never realized each variable eats a memory chunk. It seems logical now but they don't seem to mention it when teaching variables.
It would help to know that so you can think about flushing it or clean it.

I agree this has nothing to do with gpioc controller open. But if it has an 'fd' open it probably is using chunk of memory too. Correct???
 
But if it has an 'fd' open it probably is using chunk of memory too. Correct???
yes but for resources that are available as long as program runs you don't need to bother
when the program terminates in some way normal/crash they are gone anyway
you have to be careful with stuff thats recurrent allocated / freed dynamically but with something that you open at start and is needed until the program exit it's not so big deal
 
OK really dumb related programming question:

You are doing a tutorial over and over again setting
int g=15

Lets say program fails does not close or cleanup itself.
You run this program over and over learning.

Is the variable stored for "g" stored in separate memory locations or is "g" always overwritten in memory?
Put another way does each program compiled have access to this varible "g" in memory if left lingering or does it assign a new memory chunk?
Multiple "g" in memory from different programs storing it?
 
when the program terminates in some way normal/crash they are gone anyway
Depends on if you allocate the memory on the heap or on the stack. Heap memory isn't freed automatically.

Is the variable stored for "g" stored in separate memory locations or is "g" always overwritten in memory?
You can get the pointer to the memory address and print it.

C++:
#include <iostream>

int main()
{
    for (unsigned int i = 0; i < 10; ++i)
    {
        int g = 15;

        std::cout << "Memory address of g: " << &g << std::endl;
    }

    return 0;
}

output

Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630
Memory address of g: 0x7fffc8bcf630

So it uses the same memory location.
 
well when the program exists the kernel will reclaim that memory otherwise you will run out of swap several times a day.
it the memory is not reclaimable when the program exists what is the purpose of the oom killer ?
 
Yeah, the OS cleans up at termination, but this is a kiosk program which never exists. That's why you should delete heap memory after you're done with it.

I admit my example program was a bit off since it exited immediately.
 
Back
Top