FLTK logo

RE: [fltk.general] Examples create a ton of dynamic visual objects

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

RE: Examples create a ton of dynamic visual objects "MacArthur, Ian (Leonardo, UK)" Sep 30, 2016  
 
> 	Understand that when a process exits, all memory is automatically
> freed.
> 
> 	There's no such thing as a program leaking memory when it exits;
> 	all memory it allocated with new/malloc are freed by the OS.


Indeed; there are classes of thing that may persist beyond process termination, and the program does need to make explicit efforts to release these (such as named pipes used for IPC, some types of file handle, and so forth.) The actual types of things tend to vary from OS to OS, but in general they are more "specialist" anyway.

But in the general run of things, when the OS reaps an expired process it will return all the allocated memory, close off file pointers that have been left dangling and so forth, as part of the normal process clean-up.

So, whilst it is *possible* to allocate resources that persist beyond process termination, it usually takes some effort, and I'd imagine that a programmer who had done so would be "expected" to tidy up after themselves!
Normal memory allocations (new | malloc) will be reaped by the process clean-up anyway, and usually much more efficiently than you can do "manually". So they will not leak.

Leaks usually occur during runtime, when a process repeatedly allocates a block (for example in a loop) but fails to return it before the next iteration. (What it should do is return the allocation first, or (often the better choice) simply re-use the prior allocation on subsequent iterations.)


Leonardo MW Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

-- 
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.