Results 1 to 10 of 10

Thread: Application closes after displaying Crystal report several times

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2025
    Location
    Madrid, Spain
    Posts
    4

    Question Application closes after displaying Crystal report several times

    My first post in the community! I'm having a problem with my VB.NET application using Crystal Reports. I can run the same report seven or eight times in Crystal Reports, but at some point it closes without any error message. The same thing happens if I try to display it on screen or export it to PDF to view it with Acrobat. I don't think it's a Crystal runtime version issue. Any help is welcome. SAP CRystal Reports 13.0.37, same version runtime & developer version for VS.

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,959

    Re: Application closes after displaying Crystal report several times

    I'm just guessing but are you disposing and cleaning up as you do each iteration? Maybe something is "filling up" to use the technical term.
    Please remember next time...elections matter!

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2025
    Location
    Madrid, Spain
    Posts
    4

    Re: Application closes after displaying Crystal report several times

    I'm pretty sure that's the problem, but I'm using every method I know to clean up the garbage that it leaves in each interaction.


    rpt.Close()
    rpt.Dispose()


    GC.Collect()
    GC.WaitForPendingFinalizers()
    GC.Collect()

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,745

    Re: Application closes after displaying Crystal report several times

    I'll take a show in the dark here as no code is provided but are you by any chance creating multiply crystal reports for every report you run?
    Dim myreport As New CrystalReport1
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,959

    Re: Application closes after displaying Crystal report several times

    Also take a look at the task manager. Is there an app just filling it up? Sometimes I've seen that with Excel.
    Please remember next time...elections matter!

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2025
    Location
    Madrid, Spain
    Posts
    4

    Re: Application closes after displaying Crystal report several times

    Yeah, with each execution it increases by 0.3 Mb. I have searched for how to clean this garbage but I can't find it, or with what I have found I haven't been able to do it.

  7. #7
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,745

    Re: Application closes after displaying Crystal report several times

    That is insignificant . You haven't answer my question tho.

    Show the specific code that you create and show the crystal report.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2025
    Location
    Madrid, Spain
    Posts
    4

    Re: Application closes after displaying Crystal report several times

    Code:
    Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    rpt.Load(sRutaInformes & "updated\Presupuesto_Cliente.rpt", OpenReportMethod.OpenReportByDefault)
      rpt.SetParameterValue(0, EmpresaActual.IdEmpresa)
      rpt.SetParameterValue(1, _IdPresupuesto)
      rpt.SetParameterValue(2, _Version)
    cr.printrpt_GPT2(rpt, "Presupuesto Oferta")
    
    
    Public Overloads Shared Sub printrpt_GPT2(ByVal nombrereporte As ReportDocument, ByVal sDescripcion As String, ByVal ParamArray par() As String)
        Dim rpt As ReportDocument = nombrereporte
        Dim forma As New Form()
        Dim visor As New CrystalDecisions.Windows.Forms.CrystalReportViewer()
    
        Try
            ' Aplicar conexión
            logonrpt(rpt)
    
            ' Configurar visor
            visor.Dock = DockStyle.Fill
            visor.ReportSource = rpt
            visor.ShowLogo = False
            visor.ShowCopyButton = False
            visor.ShowRefreshButton = False
            visor.ShowParameterPanelButton = False
            visor.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
    
            ' Configurar formulario contenedor
            forma.Text = "Informe - " & sDescripcion
            forma.WindowState = FormWindowState.Maximized
            forma.Controls.Add(visor)
    
            ' Mostrar visor
            forma.ShowDialog()
    
        Catch ex As Exception
            MessageBox.Show("Error al mostrar el informe: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
        Finally
            Try
                ' Desvincular visor antes de liberar
                visor.ReportSource = Nothing
                forma.Controls.Remove(visor)
                visor.Dispose()
                visor = Nothing
    
                ' Cerrar formulario
                forma.Dispose()
                forma = Nothing
    
                ' Cerrar y liberar informe (si es necesario, aunque no lo clonamos)
                rpt.Close()
    
                ' Recolector
                GC.Collect()
                GC.WaitForPendingFinalizers()
                GC.SuppressFinalize(rpt)
                GC.Collect()
    
    
            Catch cleanupEx As Exception
                ' Silenciar limpieza
            End Try
        End Try
    End Sub
    Last edited by Shaggy Hiker; Mar 26th, 2025 at 03:04 PM. Reason: Added CODE tags.

  9. #9
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,745

    Re: Application closes after displaying Crystal report several times

    Where is this declared?
    Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument ?

    Also I'm drag dropping a CrystalReportViewer usually .
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,800

    Re: Application closes after displaying Crystal report several times

    This certainly sounds like a case of resources not being released. The increase in memory doesn't mean much of anything. It's cheaper for a program to ask for new memory from the system rather than recycle what it already has, so it only recycles on it's own when the system tells it to. Therefore, a slow increase up to some unknown point is reasonable behavior. What it DOES show is that more and more memory is being allocated.

    GC.Collect is usually not something you need to ever call directly. In this case, it clearly isn't solving the problem, so calling it isn't useful here, either, though it does suggest something. If every new object allocates the next chunk of memory in a sequence, then as things get disposed, the memory space for the application becomes a mix of dead objects and live objects. That state gets worse and worse until eventually no more memory can be allocated and the GC gets called to move things around, pack them into smaller area, and recover dead memory.

    That model assumes that the program can tell a live object from a dead object. Generally, dead objects can be identified because no variable holds a pointer to them, but that isn't always obvious. Well behaved objects will clean up any resources they hold when you call Dispose. You are closing a report. Does that dispose of the report? It can, as there are objects where Close leads inevitably to Dispose, but if there is a Dispose method, you should be calling that. After all, GC.Collect will recover memory that the program recognizes as being unreachable, but if some object allocated a resource, it may still be holding that resource such that GC doesn't recognize that the resource is no longer used. That would account for the behavior.

    By the way, don't expect to see the memory go down. It might, but it doesn't HAVE to. It will do whatever is most efficient, which may mean holding onto the memory, even if it isn't being used.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width