P
P
plustilino2012-08-12 13:28:48
C++ / C#
plustilino, 2012-08-12 13:28:48

dynamic structures. Is the dispose() procedure required?

In the Pascal language textbook, the procedure for removing an element from the stack is described as follows:

Procedure ReadStack(var u: pt; var dig: integer);
    var x: pt;
    begin
        dig := u^.Data;      // извлекаются данные из верхнего элемента стека
        x := u;              // сохраняется ссылка на верхний элемент
        u := u^.Next;        // вершиной стека становится следующий элемент
        Dispose(x);          // очищается память из под извлеченного элемента
    end;

Why can't it be easier?
Procedure ReadStack(var u: pt; var dig: integer);
    begin
        dig := u^.Data;     // извлекаются данные из верхнего элемента стека
        u := u^.Next;       // вершиной стека становится следующий элемент
    end;

1) I.e. in Pascal, the lack of references to a memory area does not free it?
2) Is this an example of the absence of the so-called "automatic garbage collection mechanism"?
3) It turns out that C differs from Pascal in this sense; in the first garbage is collected automatically?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TheHorse, 2012-08-12
@TheHorse

1) Pascal has no GC and no built-in smart references, and the absence of references does not change anything.
2) Yes.
3) No, C does not automatically collect garbage.

N
Nikolai Turnaviotov, 2012-08-12
@foxmuldercp

GC is definitely built into C#, and apparently in other .Net languages, although I'm not exactly sure
I think it's good form, even if it's not used in PL, maybe the OS also monitors this, I'm not a professional, so I can't say for sure can. When I wrote a batch image resize in C#, after I inserted Image.Dispose() into the ResizeImage procedure (stealed from somewhere in the network) at the end after forming the transformed image, the memory consumption was reduced by 100-200 meters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question