Click here to Skip to main content
16,015,697 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Data Access for dummies... Pin
Johnny J.12-Apr-11 21:51
professionalJohnny J.12-Apr-11 21:51 
GeneralRe: Data Access for dummies... Pin
Vimalsoft(Pty) Ltd12-Apr-11 22:01
professionalVimalsoft(Pty) Ltd12-Apr-11 22:01 
AnswerRe: Data Access for dummies... Pin
V.13-Apr-11 0:41
professionalV.13-Apr-11 0:41 
QuestionMaster/Detail works but why ? and more Pin
Jean-Louis Leroy11-Apr-11 23:19
Jean-Louis Leroy11-Apr-11 23:19 
QuestionBinding List of Objects in CommandParameter Pin
NTheOne10-Apr-11 23:30
NTheOne10-Apr-11 23:30 
AnswerRe: Binding List of Objects in CommandParameter Pin
Abhinav S11-Apr-11 1:50
Abhinav S11-Apr-11 1:50 
QuestionPolyline rendering error in silverlight Pin
chenjch10-Apr-11 5:47
chenjch10-Apr-11 5:47 
QuestionWPF/VB.NET Memory Leaks - reproducible, when creating multiple RichText controls in a WPF form. Grrrrr! Pin
JohnyPoo9-Apr-11 14:54
JohnyPoo9-Apr-11 14:54 
(Code below)

I create 200 RichTextBoxes into a collection on form load, so that I can populate a grid with them when the form is clicked.

When you click the form, it populates TestGrid with the 200 RichTextBoxes, one per row.

That part works fine, but whenever I change anything about the RichTextBoxes, like Background brush, or text, the memory just keeps on growing, each time I populate grid. I'm not ADDING text, it's the same text, every time. Nothing changes at all between grid refills.

Please, I implore you to copy this XAML and code to a new WPF project, and click on the form repeatedly, as you monitor task manager.

It's even worse if you change more properties other than text - like it can get to be 10 MB mem usage growth per refill.

I've looked on the web, to no avail. Makes no ******* sense. WTF | :WTF:

WPF is great, but: Mad | :mad:

I've read from a lot of angry people on web about WPF memory probs. None of them talked about this scenario, though, unfortunately.


<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="ScrollViewer1">
            <Grid  Name="TestGrid">
           </Grid>
        </ScrollViewer>
    </Grid>
</Window>





Imports System.Windows.Documents

Class MainWindow

    Dim Riches As New Collection
    Dim WorkRange As TextRange

    Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded

        'HERE I'M FILLING THE RICHES COLLECTION WITH 200 RICHTEXTBOXES

        Dim RichRange As Long, NewRich As RichTextBox
        For RichRange = 1 To 200
            NewRich = New RichTextBox
            Riches.Add(NewRich)
        Next

    End Sub


    Private Sub MainWindow_PreviewMouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.PreviewMouseDown

        Me.Title = "Start"

        With TestGrid
            .RowDefinitions.Clear()
            .Children.Clear()

            Dim RowRange As Long
            For RowRange = 1 To 200
                .RowDefinitions.Add(New RowDefinition)

                Dim HeaderCell As RichTextBox
                HeaderCell = Riches(RowRange)

                With HeaderCell


                    WorkRange = New TextRange(.Document.ContentStart, .Document.ContentEnd)
                    WorkRange.Text = "Poo " & CStr(RowRange)

                End With

                .Children.Add(HeaderCell)
                .SetRow(HeaderCell, RowRange - 1)
                .SetColumn(HeaderCell, 0)

            Next
        End With

        GC.Collect()

        Me.Title = "Stop"

    End Sub
End Class





If you're going to help me out and test this yourself, you can try commentizing the 2 lines of code that changes the text:

WorkRange = New TextRange(.Document.ContentStart, .Document.ContentEnd)
WorkRange.Text = "Poo " & CStr(RowRange)

By removing those two lines, no more memory growth will be visible in task manager.

Thanks a bunch!
QuestionMVVM : Assign ItemSource in View's Code Behind Pin
NTheOne8-Apr-11 23:56
NTheOne8-Apr-11 23:56 
AnswerRe: MVVM : Assign ItemSource in View's Code Behind Pin
SledgeHammer019-Apr-11 8:10
SledgeHammer019-Apr-11 8:10 
GeneralRe: MVVM : Assign ItemSource in View's Code Behind Pin
NTheOne10-Apr-11 18:15
NTheOne10-Apr-11 18:15 
GeneralRe: MVVM : Assign ItemSource in View's Code Behind Pin
Mycroft Holmes10-Apr-11 18:29
professionalMycroft Holmes10-Apr-11 18:29 
AnswerRe: MVVM : Assign ItemSource in View's Code Behind Pin
Abhinav S10-Apr-11 18:47
Abhinav S10-Apr-11 18:47 
QuestionGet Data from ViewModel in Code behind using MVVM Pin
NTheOne8-Apr-11 21:58
NTheOne8-Apr-11 21:58 
AnswerRe: Get Data from ViewModel in Code behind using MVVM Pin
Mycroft Holmes8-Apr-11 22:22
professionalMycroft Holmes8-Apr-11 22:22 
AnswerRe: Get Data from ViewModel in Code behind using MVVM Pin
Abhinav S8-Apr-11 22:35
Abhinav S8-Apr-11 22:35 
AnswerRe: Get Data from ViewModel in Code behind using MVVM Pin
SledgeHammer019-Apr-11 8:07
SledgeHammer019-Apr-11 8:07 
QuestionChange the display of a combobox control into hyperlink Pin
Rocky237-Apr-11 20:57
Rocky237-Apr-11 20:57 
AnswerRe: Change the display of a combobox control into hyperlink Pin
Mycroft Holmes7-Apr-11 22:20
professionalMycroft Holmes7-Apr-11 22:20 
AnswerRe: Change the display of a combobox control into hyperlink Pin
SledgeHammer018-Apr-11 7:57
SledgeHammer018-Apr-11 7:57 
QuestionDataGrid CellTemplate / CellEditingTemplate Pin
eddieangel7-Apr-11 9:31
eddieangel7-Apr-11 9:31 
AnswerRe: DataGrid CellTemplate / CellEditingTemplate Pin
SledgeHammer017-Apr-11 14:05
SledgeHammer017-Apr-11 14:05 
AnswerRe: DataGrid CellTemplate / CellEditingTemplate Pin
Mycroft Holmes7-Apr-11 14:36
professionalMycroft Holmes7-Apr-11 14:36 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
eddieangel8-Apr-11 6:14
eddieangel8-Apr-11 6:14 
GeneralRe: DataGrid CellTemplate / CellEditingTemplate Pin
SledgeHammer018-Apr-11 7:59
SledgeHammer018-Apr-11 7:59 

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.