title: I want my Database to not fill the RAM. What to do with images that are currently not being viewed?
body: <p><strong>What does my program do?</strong></p>
  <p>As at 05 May 2021</p>
  <p>This program was developed with the language VB.Net, the .NET framework 4.8 and with Visual Studio 2019 CE. The point of this program is to run a rudimentary database. The view is similar to a classic Internet forum—there are threads, in the threads there are different numbers of postings and in each post there are different numbers of pictures and long texts. If the thread is selected using the ComboBox, all posts with their images and texts are displayed one below the other. When you click on a specific post, only <em>its</em> images are displayed. Since the database is only intended for the company's products, it was decided not to use categories (e.g. images vs. videos vs. offtopic because it doesn't make any sense) and sub-categories (e.g. electrical vs. wood products).</p>
  <p>When the program is closed, you will be asked whether the data should be saved. (still in the beta version). These data are read in when the program is loaded. If images are not found, their paths will be displayed in a window.</p>
  <p>The user also has the option of searching through all threads and viewing the results with various sorting options. In this case, only the posts found are listed in the ListBox, and here, too, the user can select individual posts and have them displayed enlarged.</p>
  <p>The program reads in the user data when it starts. A user can log in and, depending on his role, has certain power to make decisions. A “normal” user can create threads and posts, but only an administrator or moderator can edit and delete posts; and block a user. If you are not logged in or if you are locked, you can only read threads and posts.</p>
  <p>The number of contributions is counted for each user. In the future, it should be possible to give a user stars.</p>
  <p><strong>About the classes</strong></p>
  <p>There is the <code>Form1.vb</code> class, and three other important classes: <code>Class_Forum</code>, <code>Class_Post</code> and <code>Class_Thread</code>. There is also the <code>Class_User</code> class. If a new post is created, this instance of <code>Class_Post</code> is added to a <code>List(of Class_Post)</code>, which is located in <code>Class_Thread</code> (“The thread knows which posts it has”). <code>Class_Post</code> has a member ‘Made_by’, which is an instance of the <code>Class_Users</code> (“Every post knows which user made it”). <code>Class_Post</code> contains the member ‚Bilder‘ (=Images), which is a <code>List(Of Bitmap)</code>.     That is, every instance of <code>class_post</code> has got a List(of Bitmap).</p>
  <p>There are also several forms for 1) editing, deleting posts, 2) for blocking or unblocking users, 3) for displaying enlarged images, 4) for logging in, 5) for displaying when images are not loading found, 6) to open the thread, 7) to post.</p>
  <p>When the program is started, i.e. when data is read in, the thread instances and post instances are created.</p>
  <p><a href="https://i.stack.imgur.com/N57AF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N57AF.png" alt="class diagramm" /></a></p>
  <p><strong>To do list:
  1.)</strong>
  I would like, however, that only the images are in the RAM, which belong to the thread selected with the combobox1. My question is: <em>Do I have to dispose all unnecessary images and read them in again</em> when required? Do we get that built in?</p>
  <p>This is my Code to load the data from the formatted txt file. I have a feeling, somewhere in here, or immediately after here, I have to do something.</p>
  <pre><code>Private Sub Daten_laden()
          Dim Pfad As String 'file path
          Using OFD1 As New CommonOpenFileDialog
              OFD1.Title = &quot;Textdatei auswählen&quot;
              OFD1.Filters.Add(New CommonFileDialogFilter(&quot;Textdatei&quot;, &quot;.txt&quot;))
              OFD1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
              Dim Result As CommonFileDialogResult
              Me.Invoke(Sub() Result = OFD1.ShowDialog())
              If Result = CommonFileDialogResult.Ok Then
                  Pfad = OFD1.FileName
              Else
                  Return
              End If
          End Using
  
          Dim Pruef_Anzahl_Posts_in_dem_Thread As Integer = 0 'Check number of posts in the thread 
          Dim Liste_mit_den_Pfaden As List(Of String) 'List with file paths
          Dim Liste_mit_den_Bildern As List(Of System.Drawing.Bitmap)
          'read all Text
          Dim RAT() As String = System.IO.File.ReadAllLines(Pfad, System.Text.Encoding.UTF8)
  
          Pfade_von_nicht_gefundenen_Bildern = New List(Of String) ' Paths of not found images
  
          For i As Integer = 3 To RAT.Length - 2 Step 1
              Liste_mit_allen_Threads.Add(New Class_Thread(RAT(i)))
              Me.Invoke(Sub() RaiseEvent Es_wurde_ein_neuer_Thread_eroeffnet()) 'A new thread has been opened
              Pruef_Anzahl_Posts_in_dem_Thread = CInt(RAT(i + 1))
  
              For j As Integer = (i + 2) To RAT.Length - 2 Step 1
                  Liste_mit_den_Pfaden = New List(Of String)
                  Liste_mit_den_Bildern = New List(Of Bitmap)
                  Dim Index As Integer
                  Dim Die_ID_des_Nutzers_der_den_Post_erstellt_hat As ULong = CULng(RAT(j + 4)) 'The ID of the user who created the post
                  For u As Integer = 0 To alle_Nutzer_Liste.Count - 1 Step 1
                      If alle_Nutzer_Liste(u).ID = Die_ID_des_Nutzers_der_den_Post_erstellt_hat Then
                          Index = u
                          Exit For
                      End If
                  Next
                  Dim neuerPost As New Class_Post(RAT(j), RAT(j + 1), CUShort(RAT(j + 2)), Liste_mit_den_Bildern, CDate(RAT(j + 3)), Liste_mit_den_Pfaden, alle_Nutzer_Liste(Index))
                 'how many threads are there already                
                  Dim wie_viele_Threads_gibt_es_bereits As Integer = Liste_mit_allen_Threads.Count
                  Liste_mit_allen_Threads(wie_viele_Threads_gibt_es_bereits - 1).Posts_in_diesem_Thread.Add(neuerPost)
                  ' Set the index to the last possible one in the ComboBox. This causes the program to run into the Selected Index event and SI becomes the selected index. 
                  Me.Invoke(Sub() ComboBox1.SelectedIndex = Liste_mit_allen_Threads.Count - 1)
                  j += 5
                  Do
                      Liste_mit_den_Pfaden.Add(RAT(j))
                      If System.IO.File.Exists(RAT(j)) Then
                          Liste_mit_den_Bildern.Add(New Bitmap(RAT(j)))
                      Else
                          Pfade_von_nicht_gefundenen_Bildern.Add(RAT(j))
                      End If
                      j += 1
                  Loop Until RAT(j) = &quot;#&quot; ' Marker: a post is over 
                  If RAT(j + 1) = &quot;&quot; AndAlso RAT(j + 2) = &quot;&quot; Then ' A new thread is marked with 2 blank lines one below the other.
                      i = (j + 2)
                      Exit For
                  End If
              Next
          Next
          Me.Invoke(Sub() alle_Posts_in_diesem_Thread_anzeigen()) 'show all posts in this thread
          If Pfade_von_nicht_gefundenen_Bildern.Count &gt; 0 Then ' In Case something went wrong
              Using FBNG As New Form_Bild_nicht_gefunden
                  FBNG.Datei_anzeigen(Pfade_von_nicht_gefundenen_Bildern)
                  
                  FBNG.ShowDialog()
              End Using
          End If
      End Sub
  </code></pre>
  <p>On this image, the thread is being switched using the combobox which changes the variable <code>SI</code> which I use often. In this example, the thread <code>Caucasian</code> contains 1 post which contains 2 images. <strong>Which means, (still in this moment) I don't need images form <code>shepherds</code> thread</strong>
  <a href="https://i.stack.imgur.com/zkl7Z.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zkl7Z.jpg" alt="enter image description here" /></a></p>