Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2006, 05:04 AM
Registered User
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default EXCEL process stays in memory even after deallocat

i am using EXCEL objects in a web apllication to pupulate data from a excel file. i am using code

            Dim table(,) As String
            Dim i, j As Integer
            Dim xApp As New Excel.Application
            Dim xWBS As Workbooks = xApp.Workbooks
            Dim xWB As Workbook
            Dim xWS As Excel.Worksheet
            Dim xWSS As Object
            xWBS.Open(FilePath)
            xWB = xWBS.Item(1)
            xWSS = xWB.Worksheets

            xWS = xWSS.Item(1)
            Dim xRange As Excel.Range
            xRange = xWS.UsedRange

            Dim xCols As Object = xRange.Columns
            Dim xRows As Object = xRange.Rows
            Dim xRowCount As Integer
            xRowCount = xRows.Count
            Dim xColCount As Integer
            xColCount = xCols.Count

            Dim inti, intj, iRow, iCol As Integer

            iRow = 0
            iCol = 0
            ReDim table(xRowCount, xColCount)

            For inti = 1 To xRowCount + 1
                For intj = 1 To xColCount
                    table(iRow, iCol) = xRows(inti).Cells(intj).Text.ToString()
                    table(iRow, iCol) = table(iRow, iCol).Replace("'", "''")
                    iCol += 1
                Next
                iCol = 0
                iRow += 1
            Next


            xWBS.Close()
            xApp.Quit()

            ReleaseComObject(table)
            ReleaseComObject(xRows)
            ReleaseComObject(xCols)
            ReleaseComObject(xRange)
            ReleaseComObject(xWSS)
            ReleaseComObject(xWS)
            ReleaseComObject(xWBS)
            ReleaseComObject(xWB)
            ReleaseComObject(xApp)


Private Sub ReleaseComObject(ByRef Reference As Object)
        Try
            Do Until System.Runtime.InteropServices.Marshal.ReleaseComO bject(Reference) <= 0
            Loop
        Catch
        Finally
            Reference = Nothing
            System.GC.Collect()
            System.GC.WaitForPendingFinalizers()
        End Try
    End Sub


it is working fine if i don't use this code
            For inti = 1 To xRowCount + 1
                For intj = 1 To xColCount
                    table(iRow, iCol) = xRows(inti).Cells(intj).Text.ToString()
                    table(iRow, iCol) = table(iRow, iCol).Replace("'", "''")
                    iCol += 1
                Next
                iCol = 0
                iRow += 1
            Next

when i use this code to read data from excel file then the EXCEL process stays in memory.
can anyone help
khizar,lahore,pakistan






Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu Item stays greyed out bnsteel BOOK: Beginning Mac OS X Programming 1 January 10th, 2008 02:18 PM
How to Remove Excel Object From Memory jatinp82 BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 2 May 30th, 2007 03:53 PM
Excel Application is left in Memory, why??? thetwai C# 3 March 29th, 2007 11:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.