VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,436 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,471 people online right now. Registration is fast and FREE... Join Now!




out of recources (memory problem)

 

out of recources (memory problem)

Hanzie

25 Jun, 2009 - 01:07 PM
Post #1

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 121



Thanked: 1 times
My Contributions
Hello, i have a question. i have a for..next loop in which i create many different appointments in MS Outlook.

When i start the code many outlook appointments pop-up in the background, so i see the loop is creating my appointments.

But after 2 minutes i get an error there isn't enough memory or system recources.

What can i do? I allready tried a threading.sleep(3sec.) in my program but with no succes?!

Any help?!!! Thanx

This is the code:

CODE

  Try
                        With newAppointment
                            .Start = werkdag & " " & starttijd
                            .End = werkdag & " " & eindtijd
                            .Location = "Elzenhorst"
                            .Body = "Ivonne werken"
                            .Subject = "Ivonne werken"
                            .AllDayEvent = False
                            .Recipients.Add("Hans van Neerven")
                            Dim sentTo As Outlook.Recipients = .Recipients
                            'Dim sentInvite As Outlook.Recipient
                            'sentInvite = sentTo.Add("Holly Holt")
                            'sentInvite.Type = Outlook.OlMeetingRecipientType.olRequired
                            'sentTo.ResolveAll()
                            .Save()
                            .Display(False)
                            .Close(SaveMode:=1)
                        End With
                    Catch ex As System.Exception
                        MessageBox.Show("The following error occurred: " & _
                            ex.Message)
                    End Try
                Else
                End If

            Next
            'System.Threading.Thread.Sleep(3000)


Maybe it has something to do with releasing the created outlook application?



This post has been edited by Hanzie: 25 Jun, 2009 - 01:12 PM

User is offlineProfile CardPM
+Quote Post


Jayman

RE: Out Of Recources (memory Problem)

25 Jun, 2009 - 01:13 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,544



Thanked: 226 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Without your code, it will be very difficult to offer any suggestions.

Post your code and I am sure we can provide you with an answer.
User is offlineProfile CardPM
+Quote Post

Hanzie

RE: Out Of Recources (memory Problem)

25 Jun, 2009 - 01:34 PM
Post #3

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 121



Thanked: 1 times
My Contributions
I added the code! (edited my post).
The code is in a for..next loop.

How to prevent an out of memory event when executing commands in a for..next loop?!!!

thnx in advanced.
User is offlineProfile CardPM
+Quote Post

LoveIsNull

RE: Out Of Recources (memory Problem)

25 Jun, 2009 - 01:39 PM
Post #4

Disbanding my Ignorance
****

Joined: 10 Mar, 2009
Posts: 536



Thanked: 45 times
My Contributions
It might also help to output the "string representation" of the exception to the debug window or somewhere so you can copy and paste it.
Such as:
CODE
        Try
            'Your code here...
        Catch ex As Exception
            Debug.Write("The following error occurred: " & _
        vbCrLf & ex.ToString())
        End Try


This might give you a great deal more information to go on, including the line number where the exception was thrown.

This post has been edited by LoveIsNull: 25 Jun, 2009 - 01:40 PM
User is offlineProfile CardPM
+Quote Post

Hanzie

RE: Out Of Recources (memory Problem)

2 Jul, 2009 - 11:26 AM
Post #5

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 121



Thanked: 1 times
My Contributions
Hello,

I printed the exception to a messagebox.
It's only saying that the system is out of memory.
In taskmanager i see that the cpu-usage then is at 100%

Any suggestions?

User is offlineProfile CardPM
+Quote Post

mark.bottomley

RE: Out Of Recources (memory Problem)

2 Jul, 2009 - 05:17 PM
Post #6

D.I.C Addict
****

Joined: 22 Apr, 2009
Posts: 780



Thanked: 127 times
My Contributions
First, it appears from your initial post that you positioned the commented-out Sleep after the Next statement - outside your loop.

Also, you didn't include the start of the loop in your code, so it might be generating data faster than the system can recover memory. You might try a Application.DoEvents inside the loop somewhere to allow other things to happen.

It would be interesting to add a counter to the generated appointments loop just to monitor the generation frequency - say print out every 10000.
User is offlineProfile CardPM
+Quote Post

abedjoud

RE: Out Of Recources (memory Problem)

2 Jul, 2009 - 08:21 PM
Post #7

New D.I.C Head
*

Joined: 11 Jun, 2009
Posts: 16



Thanked: 1 times
My Contributions
QUOTE(Hanzie @ 25 Jun, 2009 - 01:07 PM) *

Hello, i have a question. i have a for..next loop in which i create many different appointments in MS Outlook.

When i start the code many outlook appointments pop-up in the background, so i see the loop is creating my appointments.

But after 2 minutes i get an error there isn't enough memory or system recources.

What can i do? I allready tried a threading.sleep(3sec.) in my program but with no succes?!

Any help?!!! Thanx

This is the code:

CODE

  Try
                        With newAppointment
                            .Start = werkdag & " " & starttijd
                            .End = werkdag & " " & eindtijd
                            .Location = "Elzenhorst"
                            .Body = "Ivonne werken"
                            .Subject = "Ivonne werken"
                            .AllDayEvent = False
                            .Recipients.Add("Hans van Neerven")
                            Dim sentTo As Outlook.Recipients = .Recipients
                            'Dim sentInvite As Outlook.Recipient
                            'sentInvite = sentTo.Add("Holly Holt")
                            'sentInvite.Type = Outlook.OlMeetingRecipientType.olRequired
                            'sentTo.ResolveAll()
                            .Save()
                            .Display(False)
                            .Close(SaveMode:=1)
                        End With
                    Catch ex As System.Exception
                        MessageBox.Show("The following error occurred: " & _
                            ex.Message)
                    End Try
                Else
                End If

            Next
            'System.Threading.Thread.Sleep(3000)


Maybe it has something to do with releasing the created outlook application?


Dear Hanzie;

from what i see, you are not disposing and freeing your resources after finishing from them inside the loop. This is causing a memory leak in your application and therefore your getting the exception. my advice to you is to dispose all the variables which you used in the loop before letting it reiterate. this way you will "clog" the memory leak and aviod exception you got.

hope this helped,

Abed

User is offlineProfile CardPM
+Quote Post

Hanzie

RE: Out Of Recources (memory Problem)

4 Jul, 2009 - 05:50 AM
Post #8

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 121



Thanked: 1 times
My Contributions
Hello, you where absolutly right.
I had had to dispose the used resources. I didn't know how to do that but after googling i added the folowing code:

CODE

System.Runtime.InteropServices.Marshal.ReleaseComObject(newAppointment)
                        newAppointment = Nothing
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp)
                        oApp = Nothing
                        GC.Collect()
                        GC.WaitForPendingFinalizers()


That helped!!

Thnx biggrin.gif

User is offlineProfile CardPM
+Quote Post

Hanzie

RE: Out Of Recources (memory Problem)

16 Sep, 2009 - 09:25 AM
Post #9

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 121



Thanked: 1 times
My Contributions
Hello, it seems after all that it's not working correctly. Again i get an "out of recources" or "memory" problem with the folowing code:

CODE
Private Sub BtnExporteer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExporteer.Click

        For n As Integer = 0 To (DataGridView1.RowCount - 1) - 1

            'iJaar = "2009"
            iWeek = DataGridView1.Rows(n).Cells(0).Value.ToString

            For j As Integer = 1 To 8 - 1 'Beginnende met 1e dag (zondag) is dus getal 1

                Dim oApp As Outlook.Application = New Outlook.Application

                Dim newappointment2 As Outlook.AppointmentItem
                newappointment2 = oApp.CreateItem(OlItemType.olAppointmentItem)

                iDag = j
                werktijd = DataGridView1.Rows(n).Cells(j).Value

                If werktijd.Count > 1 Then
                    starttijd = werktijd.Substring(0, 5)
                    eindtijd = werktijd.Substring(6, 5)

                    werkdag = (Format(fnDateFromWeek(iJaar, iWeek, iDag), "dd MM yyyy")) ' mo 14 Oct 2002

                    Try
                        With newappointment2
                            .Start = werkdag & " " & starttijd
                            .End = werkdag & " " & eindtijd
                            .Location = "Elzenhorst"
                            .Body = "Ivonne werken"
                            .Subject = "Ivonne werken"
                            .AllDayEvent = False
                            .Sensitivity = OlSensitivity.olPrivate
                            .BusyStatus = OlBusyStatus.olFree
                            .Recipients.Add("Hans van Neerven")
                            Dim sentTo As Outlook.Recipients = .Recipients
                            'Dim sentInvite As Outlook.Recipient
                            'sentInvite = sentTo.Add("Holly Holt")
                            'sentInvite.Type = Outlook.OlMeetingRecipientType.olRequired
                            'sentTo.ResolveAll()
                            .Save()
                            .Display(False)
                            .Close(SaveMode:=1)
                        End With

                        Do
                            If System.Runtime.InteropServices.Marshal.ReleaseComObject(newappointment2) <= 0 Then Exit Do
                            newappointment2 = Nothing
                            GC.Collect()
                            GC.WaitForPendingFinalizers()
                            GC.Collect()
                        Loop

                        Do
                            If System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp) <= 0 Then Exit Do
                            oApp = Nothing
                            oApp.Quit()
                            GC.Collect()
                            GC.WaitForPendingFinalizers()
                            GC.Collect()
                        Loop

                    Catch ex As System.Exception
                        MessageBox.Show("The following error occurred: " & _
                            ex.Message)
                    End Try
                Else
                End If
            Next

        Next

    End Sub


I have code included for cleaning the com-object (outlook).

But it's still not working??? Tried different things, see links:

http://bytes.com/topic/c-sharp/answers/284...lication-object

http://support.microsoft.com/?kbid=317109

Please help! Thnx
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:57AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month