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?
func1()
delete p;
, p . , p . p , - . const char *p. delete, undefined. , , new delete
p
const char *p
delete
new
, - . - delete undefined.
[] ++.
- 1. delete new 2. delete[] new[].
delete[]
new[]
, . .
, .
, , delete . .
, , . Boost . : http://www.boost.org/doc/libs/1_41_0/libs/smart_ptr/smart_ptr.htm
-
, , . deleaker. , . , .
. , Test for memory leak\0 - . .
Test for memory leak\0
*p , .
*p
p, "Test for memory leak".
"Test for memory leak"
new delete. - new 'ed, deleted .
deleted
, . p - , , .
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.
deleterequired to call the allocated memory with new(only for memory obtained from the heap).
Source: https://habr.com/ru/post/1724271/More articles:How to change the primary key? - primary-keyHTML and JavaScript performance - performanceCan I add a test project later in the Asp.net MVC project? - asp.net-mvcC: What is the type of & array_name? - cHow to implement a service that can output a formula with tex parameters? - phphttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1724272/htaccess-https-to-http&usg=ALkJrhgDbq0QmXHmezMKA5y5o2HQeZkk3gNeed to send email from HTML pages - javascriptWhat is this exception: encryption buffering error in JsafeJCE JCE provider - javaWhy does my rdebug session say "*** No source file" - ruby ββ| fooobar.comhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1724276/how-to-add-weights-to-a-mysql-table-and-select-random-values-according-to-these&usg=ALkJrhhB0JeeSBvaQVV2EFdoZ8ZqMec13AAll Articles