Memory leak / memory allocation in C ++

I have the following function in C ++

void func1()
{
    char *p = "Test for memory leak";
}

When called func1(), where is the memory for the allocated variable? Be it on the stack or heap? Should it delete p;be called explicitly?

+3
source share
8 answers

, p . , p . p , - . const char *p. delete, undefined. , , new delete

+10

, - . - delete undefined.

+15

[] ++.

- 1. delete new 2. delete[] new[].

, . .

, .

, , delete . .

, , . Boost . : http://www.boost.org/doc/libs/1_41_0/libs/smart_ptr/smart_ptr.htm

-

+4

, , . deleaker. , . , .

+2

. , Test for memory leak\0 - . .

*p , .

+1

p, "Test for memory leak".

, .

new delete. - new 'ed, deleted .

, . p - , , .

, .

+1

String literals are usually located in the read-only text segment of your executable file. Calling free / uninstall on them is likely to lead to bad things.

0
source

deleterequired to call the allocated memory with new(only for memory obtained from the heap).

0
source

Source: https://habr.com/ru/post/1724271/


All Articles