0% found this document useful (0 votes)
36 views23 pages

4 Idisposable BP Csharp Developers Slides

Uploaded by

Iulian Sirbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views23 pages

4 Idisposable BP Csharp Developers Slides

Uploaded by

Iulian Sirbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Course Summary

Elton Stoneman
geekswithblogs.net/eltonstoneman
@EltonStoneman
Why write this course?

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Why write this course?

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Why write this course?

Continuous Integration Nightly Build

 Build & Test


 Build, Test & Deploy
Do Not Place Anything
in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Why write this course?

Continuous Integration Nightly Build

 Build & Test


 Build, Test & Deploy
Do Not Place Anything
in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Why write this course?

Continuous Integration Nightly Build

 Build & Test


 Build, Test & Deploy
Do Not Place Anything
in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Why write this course?

Continuous Integration Nightly Build

 
 
 
Build & Test Build, Test & Deploy
Do Not Place Anything
in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Why write this course?

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
The Best Practices

#1 #2
#6 #3
#4
#5
#7

#8

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1
Best Practice #1
Dispose of IDisposable
objects as soon as you can

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1 #2
Best Practice #2
If you use IDisposable
objects as instance fields,
implement IDisposable

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Best Practice MoSCoW

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1 #2
Best Practice #3 #3

Allow Dispose() to be called


multiple times and don't
throw exceptions

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1 #2
Best Practice #4 #3

Implement IDisposable to
#4

support disposing resources


in a class hierarchy

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1 #2
Best Practice #5 #3

If you use unmanaged #4


resources, declare a finalizer
#5

which cleans them up

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Best Practice MoSCoW

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1 #2
Best Practice
#6 #6 #3

Enable Code Analysis with


#4

CA2000 enabled – but don’t


#5

rely on it

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1 #2
Best Practice
#6 #7 #3

If you implement an interface


#4

and use IDisposable fields,


#5
#7
extend your interface from
IDisposable

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
#1 #2
Best Practice
#6 #8 #3

If you implement IDisposable,


#4

don’t implement it explicitly


#5
#7

#8

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Best Practice MoSCoW

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Using IDisposable Correctly

70000
63000 63000
60000

50000

40000

30000

20000

10000
15000
392
0
Startup First Run Multiple Runs GC.Collect

- original app Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Using IDisposable Correctly

70000
63000 63000
60000

50000

40000

30000

20000
15000
10000 12600
11000 12600
392
0 394
Startup First Run Multiple Runs GC.Collect

- original app - best practice version Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.
Summary

 Introducing IDisposable 
 Interface definition
 Unmanaged resources & other IDisposables

 What happens when the GC runs? 


 GC what and when
 Where IDisposable fits in

 What happens when you don't dispose? 


 Functional defects
 Performance problems
 How to find & fix problems

Do Not Place Anything


in This Space
(Add watermark during
editing)
Note: Warning will not appear
during Slide Show view.

You might also like