<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <atom:link href="http://titansoftware.yolasite.com/my-blog/my-blog.rss" rel="self" type="application/rss+xml" />
        <title>my-blog</title>
        <description>my-blog</description>
        <link>http://titansoftware.yolasite.com/my-blog/my-blog.php</link>
        <lastBuildDate>Sat, 13 Jun 2026 11:58:49 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>Disposing and GC</title>
            <link>http://titansoftware.yolasite.com/my-blog/my-blog/disposing-and-gc</link>
            <description>Okay, I know that no one &lt;i&gt;really&lt;/i&gt; knows or understands the GC.&amp;nbsp; I still want to touch on it briefly here.&lt;br&gt;
Some people tend to go too far when trying to prevent or cleanup memory 
leaks.&amp;nbsp; If you remember 2 simple rules, it will save you a lot of 
headache.&lt;br&gt;
1. Dispose of it when your done with it.&amp;nbsp; The Using statement is my favorite way to accomplish this.&lt;br&gt;
2. Make sure any pointers back to it are set to Nothing.&lt;br&gt;
Do this and the GC will do it's job and you wont have to over-engineer destroying everything.&lt;br&gt;
&lt;br&gt;
An example would maybe be with a list:&lt;br&gt;
&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;Dim lstCustom As New List(Of MyCustomClass) &lt;span style=&quot;color: rgb(147, 196, 125);&quot;&gt;'or whatever you want to put in it.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;For i As Integer = 0 to 10&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstCustom.Add(New MyCustomClass(i))&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;Next&lt;/div&gt;&lt;div style=&quot;color: rgb(147, 196, 125);&quot;&gt;'...do some stuff then clear the list&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;lstCustom.Clear &lt;span style=&quot;color: rgb(147, 196, 125);&quot;&gt;'this is (imho) a mistake &lt;/span&gt;&lt;/div&gt;&lt;br&gt;
lstCustom.Clear only takes the objects out of the list.&amp;nbsp; The objects 
still exist though.&amp;nbsp; Even though there arent any pointers to the 
objects, there's really no telling how long they will be floating around
 before the GC picks em up.&amp;nbsp; The way I like to handle this is to destroy
 the objects first, then remove them.&amp;nbsp; Like so:&lt;br&gt;
&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;For i As Integer = lstCustom.Count -1 to 0 Step -1&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstCustom(i).Dispose &lt;span style=&quot;color: rgb(147, 196, 125);&quot;&gt;'naturally this is only good on objects that implement IDisposable&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstCustom(i) = Nothing &lt;span style=&quot;color: rgb(147, 196, 125);&quot;&gt;'this would handle non-disposable objects&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstCustom.RemoveAt(i) &lt;span style=&quot;color: rgb(147, 196, 125);&quot;&gt;'you could do this or just wait til after the loop then call .Clear&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;Next&lt;/div&gt;</description>
            <pubDate>Sat, 29 Jan 2011 18:58:18 +0100</pubDate>
        </item>
        <item>
            <title>Index Loops vs For Each</title>
            <link>http://titansoftware.yolasite.com/my-blog/my-blog/index-loops-vs-for-each</link>
            <description>For Each loops are bad, mmmKay?&lt;br&gt;
I avoid them for 2 main reasons:&lt;br&gt;
&lt;br&gt;
1. Index loops are faster.&lt;br&gt;
2. You cant modify a list inside a For Each loop.&lt;br&gt;
&lt;br&gt;
I'll explain.&lt;br&gt;
This will fail at the remove call: &lt;br&gt;
&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;For Each str As String In lstStr&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: rgb(147, 196, 125);&quot;&gt;'test for something&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If str = &quot;boosh&quot;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; lstStr.Remove(str)&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;Loop&lt;/div&gt;It fails because you have changed the list count and therefor the index.&lt;br&gt;
&lt;br&gt;
This however, will work:&lt;br&gt;
&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;For i As Integer = lstStr.Count -1 To 0 Step -1&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: rgb(147, 196, 125);&quot;&gt; 'test for something&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If lstStr(i) = &quot;boosh&quot;&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; lstStr.RemoveAt(i)&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/div&gt;&lt;div style=&quot;color: rgb(111, 168, 220);&quot;&gt;Next&lt;/div&gt;This
 one works because we start at the bottom of the list and work up.&amp;nbsp; So 
if we remove something it only affects where we've already been.
</description>
            <pubDate>Sat, 29 Jan 2011 18:55:41 +0100</pubDate>
        </item>
    </channel>
</rss>
