Click here to Skip to main content
15,912,400 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
Nagy Vilmos24-Oct-11 21:38
professionalNagy Vilmos24-Oct-11 21:38 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
Member 205300624-Oct-11 22:17
Member 205300624-Oct-11 22:17 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
Nagy Vilmos24-Oct-11 22:24
professionalNagy Vilmos24-Oct-11 22:24 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
Member 205300624-Oct-11 22:49
Member 205300624-Oct-11 22:49 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
Nagy Vilmos24-Oct-11 23:21
professionalNagy Vilmos24-Oct-11 23:21 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
Freak3028-Oct-11 1:30
Freak3028-Oct-11 1:30 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
BobJanova25-Oct-11 23:21
BobJanova25-Oct-11 23:21 
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
Member 205300626-Oct-11 1:53
Member 205300626-Oct-11 1:53 
There is no longer a reference to it when it is finalized. The indexer returns a new object which is not stored anywhere, so goes out of scope as soon as it is created. As soon as non of the instance fields of that object can not be accessed by any code the object is eligible for finalization.

I could (and should) have prevented the finalizer from running by putting a GC.KeepAlive(this) at the end of the Reduce() method, yep, finialzers are nasty. The real code horror was not disposing of disposable objects. My bad.

A good article I found on here that mentions GC.KeepAlive is Implementing IDisposable and the Dispose Pattern Properly[^]

See point 2 in this article (OK, so this is for an old version of .net)
(MSDN article) 3.9 Automatic memory management
GeneralRe: Immutables and indexers and finalizers, oh my! Pin
BobJanova28-Oct-11 0:15
BobJanova28-Oct-11 0:15 
GeneralWe need more keys! Pin
Sander Rossel19-Oct-11 7:21
professionalSander Rossel19-Oct-11 7:21 
GeneralRe: We need more keys! Pin
fjdiewornncalwe19-Oct-11 7:30
professionalfjdiewornncalwe19-Oct-11 7:30 
GeneralRe: We need more keys! PinPopular
Sander Rossel19-Oct-11 7:45
professionalSander Rossel19-Oct-11 7:45 
GeneralRe: We need more keys! Pin
fjdiewornncalwe19-Oct-11 8:47
professionalfjdiewornncalwe19-Oct-11 8:47 
GeneralRe: We need more keys! Pin
Sander Rossel19-Oct-11 10:04
professionalSander Rossel19-Oct-11 10:04 
GeneralRe: We need more keys! Pin
BobJanova19-Oct-11 23:44
BobJanova19-Oct-11 23:44 
GeneralRe: We need more keys! Pin
Sander Rossel20-Oct-11 8:22
professionalSander Rossel20-Oct-11 8:22 
GeneralRe: We need more keys! Pin
fjdiewornncalwe20-Oct-11 9:33
professionalfjdiewornncalwe20-Oct-11 9:33 
GeneralRe: We need more keys! Pin
Hermanito7226-Oct-11 5:47
Hermanito7226-Oct-11 5:47 
GeneralRe: We need more keys! Pin
Paul Conrad20-Oct-11 7:51
professionalPaul Conrad20-Oct-11 7:51 
GeneralRe: We need more keys! Pin
Sander Rossel20-Oct-11 8:25
professionalSander Rossel20-Oct-11 8:25 
GeneralRe: We need more keys! Pin
prasun.r7-Dec-11 2:21
prasun.r7-Dec-11 2:21 
JokeRe: We need more keys! Pin
Super Lloyd22-Oct-11 0:52
Super Lloyd22-Oct-11 0:52 
GeneralDouble salvo function Pin
red_moon17-Oct-11 18:20
red_moon17-Oct-11 18:20 
GeneralRe: Double salvo function Pin
Bernhard Hiller17-Oct-11 22:46
Bernhard Hiller17-Oct-11 22:46 
GeneralRe: Double salvo function Pin
red_moon17-Oct-11 23:30
red_moon17-Oct-11 23:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.