TrueDBGrid Memory Overflow

Posted by: info on 15 November 2022, 8:12 am EST

  • Posted 15 November 2022, 8:12 am EST

    Hi to all,

    i found the following anomaly:

    Let’s imagine we have a grid that must display the photos of 1000 articles (each photo 1MB).

    I handled the situation through the FetchCellStyle with the following code:

    e.CellStyle.BackgroundImage = LoadFromFile(fullFileName);

    e.CellStyle.BackgroundPictureDrawMode = BackgroundPictureDrawModeEnum.Fill;

    If I click on the grid and quickly scroll the lines with the down arrow, the resources increase a lot until we get to the memory overflow exception.

    I had to solve using OwnerDrawCell and with the code:

    e.Graphics.DrawImage(image, rectangle);

    However the resulting code is much slower.

    Is there any way to fix?

    Thank you

  • Posted 16 November 2022, 4:47 am EST

    Hi,

    Could you please share a sample application replicating the issue with sample images that you are using, so that we can investigate the issue at our end and help you accordingly?

    Regards.

  • Posted 4 December 2022, 7:03 am EST - Updated 4 December 2022, 7:04 am EST

    Hi,

    I’ve made a small test project that throws the bug.

    It is sufficient to move to the ‘Description’ column and scroll through the elements by holding down the Down key on the keyboard.

    After about 300 lines, the System.OutOfMemoryException error is thrown.

    Regards,

    Marco

  • Posted 4 December 2022, 7:05 am EST - Updated 4 December 2022, 7:06 am EST

  • Posted 4 December 2022, 11:59 pm EST

    Hi,

    Thank You for the sample.

    We were able to observe the issue and have reported it to the development team. We will let you know as soon as we have an update.

    Regards

    Avnish

    [Tracking ID : C1WIN-28737]

  • Posted 25 April 2023, 3:28 am EST

    Hi,

    Apologies for the delay. As per the development team, the issue is from the sample and not from TrueDbGrid. The resources created by the user needs to be managed by the user, we can’t clean up user resources since we don’t know where else it is used, maybe it’s a image from the cache drawn in several more places. To work around this issue, the has suggested that you call to dispose the BackgroundImage.

    private void GridOnFetchCellStyle(object sender, FetchCellStyleEventArgs e)
    {
       e.CellStyle.BackgroundImage?.Dispose();            
       e.CellStyle.BackgroundImage = LoadFromFile(_dataTable.Rows[e.Row]["Photo"].ToString());
       e.CellStyle.BackgroundPictureDrawMode = BackgroundPictureDrawModeEnum.Fill;
    }

    You can also implement a cache to avoid creating multiple image objects for the image. Please refer to the sample attached that demonstrates how you can use a cache.

    If you face any issues, do let us know.

    Regards

    Solution_2_cache.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels