How does Singleton work | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

How does Singleton work

I know it's used for loggers but I'm not sure how it works, I would like to know when to use it and when not to use it.

18th Aug 2021, 4:43 PM
Tim
Tim - avatar
1 ответ
+ 2
Singleton used to create single object. Suppose there is a class which is accessed by many client so every time object will be create of that class and this object will be store in heap memory. So if there are 1000 client accessing that class then 1000 objects will be store in heap memory which result would be slow performance of the system. So to avoid this we use singleton.
18th Aug 2021, 5:32 PM
A͢J
A͢J - avatar