Timeline for If I need to use a piece of memory throughout the lifespan of my program, is it really necessary to free it right before program termination?
Current License: CC BY-SA 3.0
38 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 3, 2016 at 7:11 | history | tweeted | twitter.com/StackProgrammer/status/683546289888428032 | ||
| Dec 29, 2015 at 19:36 | comment | added | WGroleau | @MichaelT: I was addressing the earlier comment of whether one must free memory when there is no operating system. If there is no operating system, how are you freeing (or allocating) the memory? But your point about gdb is pertinent to the original question, i.e., it might be good to deallocate in case someone ever has to run your program with a debugger. | |
| Dec 29, 2015 at 12:29 | comment | added | user40980 | @WGroleau fire up gdb and step through another program on a single threaded system. If your operating system doesn't allocate the memory, the application running within the debugger can step on the debugger's memory. That doesn't require threads. | |
| Dec 29, 2015 at 5:55 | comment | added | WGroleau | If it is possible to reserve and free memory, that implies at least enough of an operating system to have those functions. It also implies enough of an OS to run more than on thread or program, else what would you be reserving it from? | |
| Dec 29, 2015 at 3:02 | comment | added | Eric Towers | In addition to the list at the link by AdrianMcCarthy, TCP ports (sometimes), resources held by 16-bit apps, resources held by other programs (several versions of AcroRead provided hooks for File Explorer previews, but terminated after a file chooser dialog was cancelled, leaving a stale hook and an Explorer crash during the next file chooser dialog). Previous versions of Windows failed to clean up all sorts of other resources -- brushes, OpenGL contexts, et al., et c. | |
| Dec 29, 2015 at 1:32 | comment | added | CaptainObvious | See my updated answer. I've changed the wording of "all operating systems" and "all resources" | |
| Dec 29, 2015 at 1:30 | history | edited | CaptainObvious | CC BY-SA 3.0 | added 59 characters in body |
| Dec 29, 2015 at 0:07 | comment | added | Adrian McCarthy | "the Kernel is basically guaranteed to clean[ ]up all resources" -- true for many resources, but not all. See stackoverflow.com/a/2645869/1386054 . | |
| Dec 28, 2015 at 23:08 | history | protected | Doc Brown | ||
| Dec 28, 2015 at 15:22 | comment | added | rsaxvc | @CaptainObvious Would you include a Real-time OS in "all operating systems"? I've run into some that won't free application memory when an application is unloaded. | |
| Dec 28, 2015 at 15:04 | comment | added | CaptainObvious | @EricTowers To what exception are you referring to? | |
| Dec 28, 2015 at 14:37 | comment | added | CaptainObvious | @Zaibis, I don't interpret "all operating systems" as including not having an operating system. | |
| Dec 28, 2015 at 11:03 | comment | added | Zaibis | Its about C, but related: stackoverflow.com/a/30118469/2003898 (You say your question covers all operating systems; Excluding non OS enviroments?) | |
| Dec 28, 2015 at 10:05 | answer | added | Agent_L | timeline score: 1 | |
| Dec 28, 2015 at 5:17 | answer | added | Artelius | timeline score: 1 | |
| Dec 28, 2015 at 3:16 | answer | added | Davislor | timeline score: 0 | |
| Dec 28, 2015 at 2:41 | comment | added | Eric Towers | You write: "the Kernel is basically guaranteed to cleanup all resources [...] after program termination". This is generally false, because not everything is memory, a handle, or a kernel object. But it is true for memory, to which you immediately restrict your question. | |
| Dec 27, 2015 at 20:55 | answer | added | Cort Ammon | timeline score: 3 | |
| Dec 27, 2015 at 19:13 | vote | accept | CaptainObvious | ||
| Dec 27, 2015 at 19:12 | history | edited | gnat | CC BY-SA 3.0 | title changed to better fit question text |
| Dec 27, 2015 at 17:48 | comment | added | CaptainObvious | @RichardTingle While I can't think of any other language off the top of my head other than C and maybe C++, the language-agnostic tag was meant to cover all languages that don't have much garbage collection utilities built-in. That is admittedly rare nowadays though. You could argue that you can now implement such a system in C++, but you still ultimately have the choice of not deleting a piece of memory. | |
| Dec 27, 2015 at 17:44 | history | edited | CaptainObvious | CC BY-SA 3.0 | added 334 characters in body |
| Dec 27, 2015 at 17:34 | vote | accept | CaptainObvious | ||
| Dec 27, 2015 at 18:14 | |||||
| Dec 27, 2015 at 16:13 | history | edited | user7519 | CC BY-SA 3.0 | edited body; edited tags |
| Dec 27, 2015 at 15:10 | answer | added | Peter Green | timeline score: 12 | |
| Dec 27, 2015 at 13:33 | answer | added | gnasher729 | timeline score: 1 | |
| Dec 27, 2015 at 11:25 | comment | added | Ixrec | @Brendan I think this question got a better top answer than that one, so I'm dupe-voting it to this one. | |
| Dec 27, 2015 at 11:04 | comment | added | Nikko | and of course you can write C++ without any single delete and it would be fine for memory | |
| Dec 27, 2015 at 10:32 | answer | added | Basile Starynkevitch | timeline score: 5 | |
| Dec 27, 2015 at 9:09 | comment | added | Richard Tingle | You've tagged this language agnostic but in many languages (e.g. java) it is not necessary to manually free memory at all; it happens automatically some time after the last reference to an object goes out of scope | |
| Dec 27, 2015 at 9:08 | comment | added | Brendan | See: programmers.stackexchange.com/questions/140483/… | |
| Dec 27, 2015 at 8:54 | review | Close votes | |||
| Dec 28, 2015 at 21:29 | |||||
| Dec 27, 2015 at 8:36 | answer | added | Doc Brown | timeline score: 108 | |
| S Dec 27, 2015 at 8:35 | history | edited | gnat | CC BY-SA 3.0 | Add a missing verb, and some breathing space. |
| S Dec 27, 2015 at 8:35 | history | suggested | Mat | CC BY-SA 3.0 | Add a missing verb, and some breathing space. |
| Dec 27, 2015 at 8:10 | review | Suggested edits | |||
| S Dec 27, 2015 at 8:35 | |||||
| Dec 27, 2015 at 7:40 | review | First posts | |||
| Dec 27, 2015 at 19:22 | |||||
| Dec 27, 2015 at 7:36 | history | asked | CaptainObvious | CC BY-SA 3.0 |