在.NET应用程序的内存泄漏 [英] Memory leak in .net application

查看:138
本文介绍了在.NET应用程序的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在VB.net 2005年应用程序的桌面应用程序包含了1分钟的间隔定时器。每次计时器滴答,一组函数被执行,主要是数据库相关的。 最初,应用程序运行正常。在流程(任务管理器)的CPU使用率达到100%,每定时调用时间。但是,时间跨度大约为1秒(可忽略不计)。 然而,随着时间的通行证和大约20个小时的timer_tick增加到像20-30秒的时间跨度之后。在此期间,CPU占用率100%,应用程序不响应。的timer_tick增大到1分钟,并在CPU用途逐渐的时间跨度被卡住至100%,应用程序不作出响应。 所有对象都妥善处理。 此外,这个问题是Pentium 4处理器。该应用程序正常运行的Core 2 Duo处理器。

I am working on a desktop application in VB.net 2005. The application contains a timer with an interval of 1 min. Each time the timer ticks, a set of functions gets executed, mostly database related. Initially the application runs fine. In processes(Task manager) the cpu usage goes to 100% every time the timer is invoked. But the timespan is around 1 sec(negligible). However as the time passes and after around 20 hours the time span of timer_tick increases to something like 20-30 secs. In this period cpu usage is 100% and the application does not responds. Gradually the time span of timer_tick increases to 1 min and the cpu uses gets stuck to 100% and the application does not responds. All objects are properly disposed. Moreover, this issue is with pentium 4 processors. The application runs fine on core 2 duo.

定时器包含4种功能......我加入,这些功能。

The timer contains 4 functions... I am adding few of those functions..

 Public Sub SetNotes()
    Dim dtOld As DataTable
    Dim dtNew As DataTable
    Dim oApptTasks As New AppointmentsAndTasks

    dtOld = oApptTasks.PopulateAllTasks  ' get the source table
    dtNew = dtOld.Clone  '  make new table ad clone of old table

    If btnShowNotes.Text = "Hide Notes" Then
        For Each item As System.Data.DataRow In dtOld.Rows
            If Not IsDBNull(item("Notes")) Then
                If item("Notes") <> "" Then ' add only if not null and not blank
                    item("Task") = item("Task") & vbCrLf & item("Notes") ' concatenate the notes field
                End If
            End If
            dtNew.ImportRow(item) ' import modified row to new table
        Next

        grdcTask.DataSource = SetAssignedTo(dtNew) ' set the datasource
        grdcTask.DataSource = SetAssignedFrom(grdcTask.DataSource) ' set the datasource
        repMemoNotes.LinesCount = 0 ' adjust the height of custom field
    Else
        grdcTask.DataSource = SetAssignedTo(dtOld) ' set the datasource
        grdcTask.DataSource = SetAssignedFrom(grdcTask.DataSource) ' set the datasource
    End If
End Sub

现在这是四大功能调用计时器......它采用以下code,从数据库提取数据之一。

Now this is one of the four functions called by timer...which uses the following code to fetch data from db.

  Using conn As New SqlConnection(glbSqlConnString)
        Try
            conn.Open()
            Dim dbDataAdapter As New SqlDataAdapter(oStrQueryBuilder.ToString, conn)
            dbDataAdapter.Fill(dbDataTable)

        Catch ex As Exception
            EventLog.WriteLog("App", ex.ToString, EventLogEntryType.Error)
        Finally
            If conn.State = ConnectionState.Open Then
                conn.Close()
            End If
        End Try
    End Using

很多选择,更新和删除查询的计时器进行。

Many Select, Update and delete queries are performed in the timer.

在我使用的数据库中的7000左右的记录,会出现此问题。少了记录的问题不会发生。因此,可以在SQL查询是罪魁祸首这一点。

This problem occurs when I am using around 7000 records in database. With less records the problem does not occurs. So, can the SQL queries be the culprit for this.

您可以请建议什么可能是内存泄漏的罪魁祸首?

Can you please suggest what could be the culprit in memory leak?

期待着帮助。提前致谢。

Looking forward for help. Thanks in advance.

推荐答案

我会建议使用一些探查工具。有一些免费的,但在我的经验中罗科梅工具是值得的价格。

I would recommend using some Profiler Tools. There are some free but in my experience the comercial tools are worth the price.

例如蚂蚁探查。 http://www.red-gate.com/products/dotnet-development/ Perphaps评价perios足够你?

For Example ANTS Profiler. http://www.red-gate.com/products/dotnet-development/ Perphaps the evaluation perios is enough for you ?

这篇关于在.NET应用程序的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆