| |

VerySource

 Forgot password?
 Register
Search
View: 1029|Reply: 7

Questions about dynamically applying for memory

[Copy link]

3

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-29 12:20:01
| Show all posts |Read mode
The memory space dynamically requested in C ++ must be released explicitly, so if these resources are not released at the end of the program, will the memory not be released? I read in the book that it will not be released until you restart the computer, but I tried a program and felt that the memory applied for came back at the end of the program. I observed the system availability through the task manager Memory to guess, does anyone know the exact answer
Reply

Use magic Report

0

Threads

37

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-3-2 11:00:01
| Show all posts
According to my assumption, it should be released when the program ends, and the end of a program means the release of the resources it occupies.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-2 11:30:01
| Show all posts
What program is tested?
Can junk memory be used?
Reply

Use magic Report

0

Threads

3

Posts

53.00

Credits

Member

Rank: 2

Credits
53.00

 China

Post time: 2020-3-2 11:38:47
| Show all posts
The dynamically requested memory space in C ++ must be released explicitly. If the release is not displayed, the operating system will reclaim the requested memory when the program exits. But system kernel resources (such as some resource handles with counters) are not reclaimed.
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-3-2 21:45:02
| Show all posts
Landlord, the book you read is too old, it is still a book in the dos era.
In virtual memory mode, system resources are automatically reclaimed when a process exits.
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-3-3 09:15:01
| Show all posts
Dynamic application is heap memory, if there is no automatic memory reclamation mechanism (Yes in Java, C ++ does not)
The requested memory will not be automatically reclaimed at the end of the process, that is, a memory leak

C ++ automatically releases stack memory
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-3-4 10:15:01
| Show all posts
>> "If these resources are not released at the end of the program, will the memory not be released? What I read in the book is not released until you restart the computer."

This is a mess in the book. Different platforms and different systems deal with this problem differently, but for most modern operating systems, it is unlikely that they will not be released.

However, for "memory leaks", the more important thing is what to do when your program is running? Really useful programs, unlike the practice programs that we usually write, end in a few simple steps, but start in a few hours, a few days, and execute thousands of cycles, even like a bank system It runs day after day without shutting down. At this time, if one byte is leaked on average per cycle, the consequences are unthinkable.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Invalid IP Address

Post time: 2020-3-11 05:30:02
| Show all posts
Non-release refers to the situation where the process has not ended. Once the program exits, even the NEW memory in the program will be recycled. Ha ha.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list