How is a executable erased from memory?

Asked

Viewed 58 times

2

Sorry if this question seems repeated but is this question did not answer what I wanted to know:as a program is loaded into memory

The .exe is loaded whole into memory or parts of the program are called only when needed?

After this part of the program is used (for example a summing function) is it totally discarded from memory after it is used? Or just the result stays there? Or maybe this function stays totally there until we close the program? Or maybe she’s discarded until she’s called?

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site

1 answer

3

It is not erased. Simple as that. And this can be a security problem if it kept sensitive data in memory. Not that this is any less of a problem while it’s running, but if something happens that you don’t know about and has sensitive data the damage potential is greater.

Executable

When you talk about an executable you are talking about the static and fixed part that is inside a binary file contained in mass storage, and if you read the question linked (and the links contained there) with attention will see that it goes to the memory circumstantially through the virtual memory. And that at the end of its execution does not need to do anything with it, simply the operating system marks that the memory pages that have the mirroring of what is on disk (or SSD or NVRAM, although this could even dispense with mirroring, but it is another matter) are no longer in use, and that’s it. It’s practically changing a few bits in control in the operating system at the end of it. And it doesn’t change anything else because what would be in the memory is already on the same "disk".

Of course these pages are free to be used by any other processing, so at some point something will be written over it and it will cease to exist, but there is no need to go to any trouble to erase something. This needs to be made clear.

Memoriam

Your application will still consume memory to perform everything it needs. In general it will do so in two known concepts like stack and heap, but for our purpose here we don’t even need to understand that part. We just need to know that all memory needed for the application, one way or another, will be delivered by the operating system as requested. The operating system has an accounting of everything (in this case memory pages) that it delivered to an application (it has a simple "database" in memory with it).

The operation of this delivery is equal to the executable, in the matter of virtual memory has a mirror to the mass memory, but unlike the executable that starts from the "disk" to mirror in RAM, this transient memory part of the RAM and only goes to the mass memory ("disk") if it really is absolutely necessary, which is the so-called swap memory that should never happen in applications that behave and wish to have good performance (every time it does swap the execution time becomes tragic, to say something condescending).

So when the application is finished, these memory pages are marked by the operating system, it is part of its task, as free pages for reuse in any OS need. Simple and fast like this (in many cases it will be below a microsecond, at least that part, it may take longer for the application itself to do the shutdown).

And precisely because nothing is erased can be insecure and another application see that "unintentionally". Some languages clean up what you use, others let you do it, and when I say clean up, it’s often not even something that’s actually done, the cleaning can be just write something on top of what you already had for direct use at the time of using, but it’s still all there.

Completion

There must be tools to do some cleaning if necessary, but in general if you need to erase then do before finishing the application, or better yet, do not put in memory something sensitive, because nothing guarantees that it will be erased even, various situations can occur and prevent this.

What you need to understand most about all this is virtual memory. I think there is something specific and direct but the link of question in What is memory segmentation? is already a start to start researching more.

As to the question of enforceable burden, the answer linked answers perfectly what you want to know, just read carefully. I’m just answering the part of the ending that doesn’t actually speak in detail there and one would have to infer that it is so (some get it, others don’t, so I’m answering).

  • I was going to lynch in a comment to the AP next to Stack and Heap this one What is Garbage Collector, but as you already gave an answer. The comment has lost its meaning. See it serves as a complement.

  • 2

    I don’t even think it makes sense, GC has nothing to do with it, actually stack and heap, The O.R.’s not aware of that. It would be nice if the OS had a mechanism to at least help GC, it would be much better, amazing that even after almost all languages use something like this it still doesn’t have. The question here is about something other than application memory management.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.