Home > Back-end >  C the singleton pattern
C the singleton pattern

Time:09-24

See online a lot of discussion about the singleton pattern, the destruction of the singleton pattern is the most controversial issues,
See a lot of, this is accurate, if there is no implicit call use function or explicitly call, the system will not perform the object's destructor, but system do all the process of recycling,
My last point
1 if you don't need the destructor in the static object performs some necessary operation, I feel it is not necessary to superfluous action, static objects are ultimately with application life cycle, the program will be over, in addition to the business process logic, we also need to do what?

Hope which the great spirit can be overturned, give a if you don't release the singleton, program or a system problem?

My another question also nobody answer, attach ads on http://bbs.csdn.net/topics/392027199? Page=1 # post - 401640563

CodePudding user response:

CodePudding user response:

I student, not good at communication, I am back to read my questions, as if a little rushed, hope which great god mention bill of lading example model needs to automatically or manually destructor is not?

CodePudding user response:

The building Lord understand correctly, first of all, for the operating system can approximate understanding to the allocation of system resources and recycling are carried out in accordance with the process as the unit,

Each time we write the EXE program to run in the operating system has a process, a 32-bit operating system for the process in advance to prepare the 4 g memory address space (not the actual distribution of so many, only address range), our EXE program in running, no matter how to allocate memory, destruction of memory, are conducted in the 4 gb address space, so no matter how much memory resources to apply for in the program is running, when the process is destroyed, the process of all memory resources are WIN recycling, equivalent to the 4 gb one-time recovery, so not a memory leak,

Now we usually say that the memory leak, the main is to point to in the process of the program is running, in 4 gb address space applied for memory, and no release, cause the program is not over yet, will 4 gb address space is used up, cause the program available resources depletion and collapse,

Generally speaking, good habits is the application and release the one-to-one correspondence, of course, as long as enough system resources, the program will not collapse because no resources available, will not affect the operating system itself is slow, so the new object does not release also no big deal,
  • Related