Click here to Skip to main content
15,886,199 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: :'-( Pin
woosterprogrammer7-Aug-12 1:49
woosterprogrammer7-Aug-12 1:49 
GeneralRe: :'-( Pin
Schmuli7-Aug-12 21:03
Schmuli7-Aug-12 21:03 
GeneralRe: :'-( Pin
woosterprogrammer8-Aug-12 1:28
woosterprogrammer8-Aug-12 1:28 
GeneralRe: :'-( Pin
BobJanova1-Aug-12 23:00
BobJanova1-Aug-12 23:00 
GeneralRe: :'-( Pin
Pete O'Hanlon1-Aug-12 23:09
mvePete O'Hanlon1-Aug-12 23:09 
GeneralRe: :'-( Pin
BobJanova2-Aug-12 1:38
BobJanova2-Aug-12 1:38 
GeneralRe: :'-( Pin
CDP18022-Aug-12 3:31
CDP18022-Aug-12 3:31 
GeneralRe: :'-( Pin
bjarneds1-Aug-12 23:31
bjarneds1-Aug-12 23:31 
Relying on the GC to clean up after classes that implements IDisposable may be dangerous - in some cases such a class may never be garbage collected and thus in practice lead to memory leaks.

Consider a class that e.g., when instantiated, subscribes to an event from .NET's SystemEvents class (a GUI application might e.g. subscribe to UserPreferenceChanged). Because these events are static, the delegate have a reference to the class that lasts for the entire lifetime of the application, i.e. it will prevent the class from being GC'ed until it unsubscribes from the event. I.e. the user of the class will have to tell it when it no longer needs to subscribe to such an event - the obvious way to do that is by calling Dispose.

Now, you could argue that not all classes that implements Dispose suffer from this, but how would you know (and know that a future version of the class wouldn't require it either)? And should you know - is it not the purpose of encapsulation to ensure that you don't have to know about implementation details like this?

Due to this, in my opinion is should not only be best practice, but required that you call Dispose on a class that implements IDisposable.
GeneralRe: :'-( Pin
Gary Huck1-Aug-12 3:40
Gary Huck1-Aug-12 3:40 
GeneralRe: :'-( Pin
Schmuli1-Aug-12 3:01
Schmuli1-Aug-12 3:01 
GeneralRe: :'-( Pin
Dave Kreskowiak1-Aug-12 4:59
mveDave Kreskowiak1-Aug-12 4:59 
GeneralRe: :'-( Pin
reilly961-Aug-12 7:42
reilly961-Aug-12 7:42 
GeneralRe: :'-( Pin
spencepk3-Aug-12 14:37
spencepk3-Aug-12 14:37 
GeneralRe: :'-( Pin
AspDotNetDev3-Aug-12 14:43
protectorAspDotNetDev3-Aug-12 14:43 
GeneralRe: :'-( Pin
Thornik6-Aug-12 9:57
Thornik6-Aug-12 9:57 
GeneralTo check for updates, install an update for Windows Update Pin
Divya Rathore26-Jul-12 21:33
Divya Rathore26-Jul-12 21:33 
GeneralRe: To check for updates, install an update for Windows Update PinPopular
OriginalGriff26-Jul-12 22:07
mveOriginalGriff26-Jul-12 22:07 
GeneralRe: To check for updates, install an update for Windows Update Pin
Divya Rathore26-Jul-12 23:15
Divya Rathore26-Jul-12 23:15 
GeneralRe: To check for updates, install an update for Windows Update PinPopular
OriginalGriff27-Jul-12 0:28
mveOriginalGriff27-Jul-12 0:28 
GeneralRe: To check for updates, install an update for Windows Update Pin
Divya Rathore27-Jul-12 0:30
Divya Rathore27-Jul-12 0:30 
GeneralRe: To check for updates, install an update for Windows Update Pin
Eddy Vluggen30-Jul-12 3:21
professionalEddy Vluggen30-Jul-12 3:21 
GeneralRe: To check for updates, install an update for Windows Update Pin
OriginalGriff30-Jul-12 3:36
mveOriginalGriff30-Jul-12 3:36 
GeneralRe: To check for updates, install an update for Windows Update Pin
Eddy Vluggen30-Jul-12 3:22
professionalEddy Vluggen30-Jul-12 3:22 
GeneralBang Head! Pin
VallarasuS24-Jul-12 20:40
VallarasuS24-Jul-12 20:40 
GeneralRe: Bang Head! Pin
BillW3326-Jul-12 3:58
professionalBillW3326-Jul-12 3:58 

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.