I read in images from a file location to a collection of bitmapimages and use the collection of bitmapimages as the Image.Source for image controls that i display on screen. However i seem to be getting bad memory leaks as the garbage collector does not seem to realize its time to dispose of the Image objects after they should be.
i clear all the children in all the containers and it still doesnt dispose of the images, so the memory builds up to like 1000mb... anyone have any idea? thanksCode:Dim x As Int32 = 0 For x = 1 To pictureCount Dim picbox As New Image Dim rand As Int32 Do rand = RandomNumber(collectionPictures.Count, 1) Loop While PicExists(rand) = True picbox.Source = CType(collectionPictures.Item(rand), ImageSource) picbox.Margin = New Thickness(5) picbox.Name = "picBox" & rand.ToString collectionUsedPics.Add(rand) Grid.SetRow(picbox, picRow) Grid.SetColumn(picbox, picCol) Grid.SetRowSpan(picbox, 1) If picCol = 1 Then Grid.SetRowSpan(picbox, 2) picbox.MaxHeight = 650 End If If picCol = 1 And picRow = 1 Then Grid.SetRow(picbox, 1) Grid.SetColumn(picbox, 2) End If gridContent.Children.Add(picbox) picCol = picCol + 1 If picCol > 2 Then picCol = 0 picRow = picRow + 1 End If Next x Container.Children.Add(gridContent)




Reply With Quote