OutOfMemoryException

11 posts, 0 answers
  1. LH
    LH avatar
    1 posts
    Member since:
    Aug 2011

    Posted 03 Sep 2014 Link to this post

    Hi, 
    I have PDF files that contains of several pages but with only 2 MB more or less.
    When the RadPdfViewer loads the document a OutOfMemoryException occured. 
    CallStack: 

    Insufficient memory to continue the execution of the program.

       at System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette)
       at Telerik.Windows.Media.Imaging.RadBitmap..ctor(Int32 width, Int32 height, Int32[] pixels)
       at Telerik.Windows.Documents.Fixed.UI.UIElementsHelper.CreateImageSource(ResourceKey key, ImageSource source)
       at Telerik.Windows.Documents.Fixed.UI.UIElementsHelper.ImageLoader_WorkCompleted(Object sender, WorkCompletedEventArgs e)
       at Telerik.Windows.Documents.Core.Utils.ResourceLoader.OnWorkCompleted(WorkCompletedEventArgs args)
       at Telerik.Windows.Documents.Core.Utils.ResourceLoader.Worker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
       at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
       at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 08 Sep 2014 Link to this post

    Hello LH,

    I suggest we continue the conversation in the support ticket that you opened on the topic, as attachments  are not available in the public forums.

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Frank
    Frank avatar
    3 posts
    Member since:
    Jul 2013

    Posted 30 Sep 2014 in reply to Petya Link to this post

    Hi,

    I would like to hoop up to this thread since I have quite a similar problem. The PDF in question is just 253kb in size, but grows up to approx. 300MB in memory, which, in some occasions, is a dead trap for some of our users with only 2GB of memory.

    If needed, I can provide the PDF in question. Otherwise: Any general suggestions or options?

    Cheers,

    Frank
  5. Frank
    Frank avatar
    3 posts
    Member since:
    Jul 2013

    Posted 30 Sep 2014 in reply to Frank Link to this post

    Hi again,

    I would like to be a bit more precise, since I have examined the problem a bit further just now.

    The PDF contains a couple of large monochrome images, here is the header of one of the images from the PDF:

    <</Subtype/Image /Width 3150 /Height 2175 /BitsPerComponent 1 /ColorSpace/DeviceGray /Filter/CCITTFaxDecode /DecodeParms<</K -1/EndOfBlock false/Columns 3150>>

    I assume that the RadPdfViewer is rendering the images in full size using RadBitmap - while using the internal 32 Bit ARGB Format.

    If I am correct about that, I would like to write a custom filter for CCITT (which should be the TIFF filter).

    Questions are:

    1.) Am I correct about the issue that images are rendered in full size using RadBitmap in 32Bit?
    2.) Is there any chance to use RadBitmap NOT using ARGB, but e.g. monochrome?

    Cheers,

    Frank
  6. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 02 Oct 2014 Link to this post

    Hello Frank,

    Thank you for your interest in RadPdfViewer.

    You are correct, RadPdfViewer uses full size 32bit bitmap to store the decoded images. Your idea is interesting and we will definitely look into the possibility of implementing it the next time we schedule some memory optimizations, so thank you for the feedback. You can track the status of the issue through this item in the public portal

    Unfortunately at this point only ARGB format is supported and this cannot be changed by replacing the CCITTFaxDecode.

    Hope this answers your questions.
     
    Regards,
    Kammen
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  7. Frank
    Frank avatar
    3 posts
    Member since:
    Jul 2013

    Posted 02 Oct 2014 in reply to Kammen Link to this post

    Hi Kammen,

    thanks for the feedback. I checked it right after my last comment and also found out that this was impossible to solve via the decoder.

    Anyway, it's good to see that the issue made it to the feedback portal and I hope that matter could be solved during your developers' next RadPdfViewer roundup.

    Thanks again,

    Frank
  8. Md. Morshed
    Md. Morshed avatar
    6 posts
    Member since:
    Sep 2010

    Posted 24 Jun Link to this post

    I am using Telerik version 2016 Q2 trial and I am still getting this "OutOfmemeoryException". Is it fixed ? Since I have found it working in your official Demo for RadPdfViewer. I dont know what else you have done in that demo project.Thanks in advance.
  9. Md. Morshed
    Md. Morshed avatar
    6 posts
    Member since:
    Sep 2010

    Posted 24 Jun Link to this post

    Please note that I have use the same code you have in you demo and its not working for me. whenever I am trying to load a big pdf . It is getting out of memory exception. 
  10. Md. Morshed
    Md. Morshed avatar
    6 posts
    Member since:
    Sep 2010

    Posted 24 Jun in reply to Md. Morshed Link to this post

    Please note the Page up and page down is also not working for me. Please let me know what wrong in my code.

     

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <telerik:RadToolBar DataContext="{Binding ElementName=pdfViewer, Path=CommandDescriptors}">
                    <telerik:RadButton Command="{Binding OpenCommandDescriptor.Command}" Visibility="{Binding OpenCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Open" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=open.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <telerik:RadButton Command="{Binding PrintCommandDescriptor.Command}" Visibility="{Binding PrintCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Print" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=printer.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <telerik:RadToolBarSeparator/>

                    <telerik:RadButton x:Name="counterClockwiseButton"
                                        Command="{Binding RotateCounterClockwiseCommandDescriptor.Command}"                                    
                                        Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Rotate counterclockwise" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=rotate-counterclockwise.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <telerik:RadButton x:Name="clockwiseButton"
                                        Command="{Binding RotateClockwiseCommandDescriptor.Command}"                                    
                                        Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Rotate clockwise" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=rotate-clockwise.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <telerik:RadToolBarSeparator/>

                    <telerik:RadButton Command="{Binding PageUpCommandDescriptor.Command}" Visibility="{Binding PageUpCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"  HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Previous page" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=previous.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <telerik:RadButton Command="{Binding PageDownCommandDescriptor.Command}" Visibility="{Binding PageDownCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Next page" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=next.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <TextBox Width="45" Margin="2" Text="{Binding FixedDocumentViewer.CurrentPageNumber, Mode=TwoWay}" HorizontalContentAlignment="Center" x:Name="tbCurrentPage" KeyDown="tbCurrentPage_KeyDown"/>
                    <TextBlock VerticalAlignment="Center" Margin="2" Text="/" />
                    <TextBlock VerticalAlignment="Center" Margin="2" Text="{Binding FixedDocumentViewer.PagesCount}" />
                    <telerik:RadToolBarSeparator/>

                    <telerik:RadButton Command="{Binding ZoomInCommandDescriptor.Command}" Visibility="{Binding ZoomInCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Zoom in" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=zoom-in.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <telerik:RadButton x:Name="PART_btnZoomOut" Command="{Binding ZoomOutCommandDescriptor.Command}" Visibility="{Binding ZoomOutCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Zoom out" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=zoom-out.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadButton>

                    <telerik:PercentComboBox Value="{Binding ElementName=pdfViewer, Path=ScaleFactor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                                RadPdfViewer="{Binding ElementName=pdfViewer}"
                                                Margin="2">
                        <telerik:PercentComboBox.PercentValues>
                            <telerik:Percent Value="10"/>
                            <telerik:Percent Value="25"/>
                            <telerik:Percent Value="50"/>
                            <telerik:Percent Value="75"/>
                            <telerik:Percent Value="100"/>
                            <telerik:Percent Value="150"/>
                            <telerik:Percent Value="200"/>
                            <telerik:Percent Value="500"/>
                            <telerik:Percent Value="1000"/>
                            <telerik:Percent Value="2000"/>
                        </telerik:PercentComboBox.PercentValues>
                    </telerik:PercentComboBox>

                    <telerik:RadToolBarSeparator />
                    <telerik:RadToggleButton x:Name="fitToWidthButton"
                                         Command="{Binding FitToWidthFixedDocumentPagesPresenterCommandDescriptor.Command}"
                                         IsEnabled="{Binding FitToWidthFixedDocumentPagesPresenterCommandDescriptor.IsEnabled, Converter={StaticResource InvertedBooleanConverter}, Mode=TwoWay}"
                                         IsChecked="{Binding FitToWidthFixedDocumentPagesPresenterCommandDescriptor.IsEnabled, Mode=TwoWay}"
                                         Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Fit to window width and enable scrolling." />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=document-fit-width.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadToggleButton>

                    <telerik:RadToggleButton x:Name="fitToPageButton"
                                        Command="{Binding FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.Command}"
                                        IsEnabled="{Binding FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.IsEnabled, Converter={StaticResource InvertedBooleanConverter}, Mode=TwoWay}"
                                        IsChecked="{Binding FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.IsEnabled, Mode=TwoWay}"
                                        Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Fit one full page to window." />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=document-fit-page.png, IconSources={StaticResource IconPaths}}" Stretch="None" />

                    </telerik:RadToggleButton>
                    <telerik:RadToolBarSeparator />

                    <telerik:RadToggleButton IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=Pan}" Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Pan" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=hand-free.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadToggleButton>

                    <telerik:RadToggleButton IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=TextSelection}" Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
                        <ToolTipService.ToolTip>
                            <TextBlock Text="Text Selection" />
                        </ToolTipService.ToolTip>
                        <Image Source="{telerik:IconResource IconRelativePath=text-selection.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
                    </telerik:RadToggleButton>
                </telerik:RadToolBar>

                <telerik:RadPdfViewer Grid.Row="1" x:Name="pdfViewer" DocumentSource="/PdfViewer;component/SampleData/Sample.pdf" DataContext="{Binding ElementName=pdfViewer, Path=CommandDescriptors}">
                    <telerik:RadContextMenu.ContextMenu>
                        <telerik:RadContextMenu x:Name="menu">
                            <telerik:RadMenuItem Header="Copy" Command="{Binding CopyCommandDescriptor.Command}"
                                            Visibility="{Binding CopyCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
                            <telerik:RadMenuItem Header="Select All" Command="{Binding SelectAllCommandDescriptor.Command}"
                                            Visibility="{Binding SelectAllCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
                            <telerik:RadMenuItem IsSeparator="True"
                                            Visibility="{Binding TextSelectionCommandDescriptorsGroup.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>

                            <telerik:RadMenuItem IsCheckable="True" IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=Pan}" Header="Pan" />
                            <telerik:RadMenuItem IsCheckable="True" IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=TextSelection}" Header="Text Selection" />

                            <telerik:RadMenuItem IsSeparator="True"
                                            Visibility="{Binding ViewCommandDescriptorsGroup.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>

                            <telerik:RadMenuItem Header="Zoom In" Command="{Binding ZoomInCommandDescriptor.Command}"
                                            Visibility="{Binding ZoomInCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>

                            <telerik:RadMenuItem Header="Zoom Out" Command="{Binding ZoomOutCommandDescriptor.Command}"
                                            Visibility="{Binding ZoomOutCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
                            <telerik:RadMenuItem IsSeparator="True" />

                            <telerik:RadMenuItem Header="Print" Command="{Binding PrintCommandDescriptor.Command}"
                                            Visibility="{Binding PrintCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>

                            <telerik:RadMenuItem Header="Find" Command="{Binding ShowFindDialogCommandDescriptor.Command}"
                                            Visibility="{Binding ShowFindDialogCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
                        </telerik:RadContextMenu>
                    </telerik:RadContextMenu.ContextMenu>
                </telerik:RadPdfViewer>
            </Grid>

  11. Bryand
    Bryand avatar
    3 posts
    Member since:
    Nov 2015

    Posted 27 Jun Link to this post

    I am also getting an out of memory exception and I don't understand why. The computers that are running into this issue are beefed up with 24gb of ram, and 1TB of storage. And the file they are having issues rendering is a simple two page document with less than 100kb. Why is this happening?
  12. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 29 Jun Link to this post

    Hi all,

    @Md. Morshed, I checked the code you provided and couldn't find anything suspicious in it. As you said you tested the document in our demos and it is properly imported, I suppose that there is something related to the setup. However, I cannot say what it might be looking at the XAML.

    You could download the source code of our examples from your account and check what is the difference in your project. The archive file containing the code is available on our website - just log in at www.telerik.com, go to Downloads and select UI for WPF. You will find a list of all the available for download files according to your license. The .zip file with the examples is called Telerik_UI_for_WPF_[version]_Demos.zip.

    If you are still having issues with this, you could open a support ticket and send us the project so we can check what might cause the behavior you are experiencing.

    @Bryand, at this point, we are unaware of an issue in RadPdfViewer that may cause an OutOfMemoryException in such a simple document. With our latest version (R2 2016 SP1), we introduced improvements in the memory usage of the control. Could you test the document with this version if you haven't yet? You could try if it opens in our online examples as well.

    If you are still getting this exception, could you send us this document to test it locally? Please, note that the public forums allow you attaching only images and you may need to submit a support ticket where you can attach this document as a .zip file.

    Regards,
    Tanya
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready