Urgent.News

What's breaking now, across thousands of outlets.

Tech

Como os programas rodam na memória

Bom, continuando o tópico, ainda estamos falando sobre fundamentos. Como os programas rodam na memória. Um programa é um arquivo parado no disco. Quando ele é executado, o sistema operacional copia ele para a RAM e cria um processo: O programa em execução, com sua própria área de memória. É possível ter vários processos do mesmo programa ao mesmo tempo. O sistema operacional dá a cada processo um…

Original Portuguese Read in English

When discussing the fundamentals of how programs run in memory, it's important to understand that a program is a halted file on the disk. Upon execution, the operating system copies the program into RAM and creates a process for it. This process has its own dedicated memory area. Multiple processes of the same program can run simultaneously. The operating system assigns each process an isolated memory space, ensuring security and stability. If one process crashes, the others continue functioning.

Two key concepts in this context are Stack and Heap. Each time a function is called, a block is added to the top of the stack, containing the function's local variables and the return address. Once the function finishes, the block is removed. This process is automatic, swift, but limited in size and predefined. This is the Stack.

Data that persists beyond a function call or whose size is only known at runtime, like dynamically allocated objects, reside in the Heap. The Heap is larger and more flexible, but managing it is slower.

In C#, memory management is handled by the Garbage Collector. The Heap is cleaned by the Garbage Collector, which can only remove objects no longer referenced, such as classes created in a loop. However, if such a class is added to a collection, the Garbage Collector won't find it, leading to memory leaks. It's essential to know these concepts, as I've recently decided to learn from scratch, and I'll be sharing more content on this topic soon.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 29 September →