0

I would like to know is there any problem if we are not clearing or deleting an object that scope is complete program.

I believe the OS will cleanup the memory after executing the application.

This object is not going to use any socket or file operation, it will just allocate some memory for storing some data. may be int * x = new int[100];

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Gilson PJ
  • 3,443
  • 3
  • 32
  • 53
  • 4
    See here: http://stackoverflow.com/questions/273209/are-memory-leaks-ever-ok – hauron Jul 12 '16 at 07:37
  • As a side note: if the memory consumption (or leaking) is not a problem, it may be more performant to skip some desctructors and just exit (although - sloppy, and might hurt if the design changes). – hauron Jul 12 '16 at 07:40
  • I agree with the accepted answer at the duplicate question: yes, you may decide to leave some leaks and hope that the OS removes them, but a) it looks sloppy, reducing confidence in your code and b) why take the time to decide that this one is no problem, instead of consistently removing all of them, without having to make decisions (nd the possiblity of being wrong). IOW, it is part of discipline. – Rudy Velthuis Jul 12 '16 at 07:48
  • Don't spam tags! This is not C. – too honest for this site Jul 12 '16 at 07:55
  • Thanks actually I got this question from an interviewer and I couldn't get a proper answer from anywhere. @Olaf I know this is not a C question but the question is related to dynamic memory allocation. I have added a very simple example in C++ but I thought any C developers can understand that example. Also I believe dynamic memory allocation and memory leaks are also the part of C. – Gilson PJ Jul 12 '16 at 08:00
  • Nonsense, with the same argument you could add Python and Assembler tags. C and C++ are different languages and they can use different management schemes. – too honest for this site Jul 12 '16 at 08:07

0 Answers0