Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Special syntax on Using
Message
 
To
11/02/2014 15:33:45
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01594076
Message ID:
01594123
Views:
42
>>You should get to the reason the memory usage increases then figure out how to resolve the issue.
>
>Yes, but this is very difficult to find. That is why the first step was to implement the Using approach where it applies. This seems to be related to the implementation of SOAP SVC. I have it at one location in the framework and the application using it seems to obtain a side effect from it. So, in the application, I have added the Using approach on the initialization of the SOAP SVC service and so far the memory stands straight.

Maybe you can wrap the "unmanaged" class you want to be USING into a class that does implement iDisposable. That's what I did with Excel, and it works reasonably well.

Please have a look at how I "iDisposable"d my wrapped excel class.

I'm using the Using construct with it, and it does dispose of the object once it goes out of scope. (I.e. excel does not remain in the task list). It's what you are supposed to do when you don't want to wait for the garbage collector to get rid of the "unmanged" classes.

Don't ask me how it works.... I have no clue.
Imports Microsoft.Office.Interop
Public Class fwExcel
    Implements IDisposable
    Public oApp As New Excel.Application
    Public oWBs As Excel.Workbooks
    Public oWB As Excel.Workbook

    Dim thisThread As System.Threading.Thread
    Dim lQuit As Boolean = True
    Dim lDisposed As Boolean = False

    Sub New()
        Me.thisThread = System.Threading.Thread.CurrentThread
        Me.originalCulture = thisThread.CurrentCulture
        Me.thisThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
        Me.oWBs = Me.oApp.Workbooks
        Me.oApp.DisplayAlerts = False
    End Sub
    Sub Dispose() Implements IDisposable.Dispose
        If Me.lDisposed Then Exit Sub
        If lQuit Then Me.oApp.Quit()
        Me.releaseObject(Me.oWB)
        Me.releaseObject(Me.oWBs)
        Me.releaseObject(Me.oApp)
        Me.thisThread.CurrentCulture = Me.originalCulture
        Me.lDisposed = True
    End Sub
    Protected Overrides Sub finalize()
        Me.Dispose()
    End Sub
    Public Sub releaseObject(ByVal o As Object)
        If o Is Nothing Then Exit Sub
        Runtime.InteropServices.Marshal.FinalReleaseComObject(o)
        o = Nothing
    End Sub

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform