0

So, basically what I'm doing is logging into a lotus notes database and pulling some information. however it's not releasing the objects after I'm done. this is causing issues. if I run this code wait until it's done and then go check names.nsf it will still be in use no matter what I try. hopefully SO master coders can help me out :) thanks!

NotesSession ns = new NotesSession();
NotesDatabase ndb;
NotesView nview;
NotesDocument doc;
try
{
    ns.Initialize();
    ndb = ns.GetDatabase("server", @"database",false);
    nview = ndb.GetView(@"view");
    doc = nview.GetFirstDocument();
    ListViewItem notesrow = new ListViewItem();
    while (doc != null)
    {
        notesrow = new ListViewItem();
        if (doc.HasItem("variable0") && doc.HasItem("variable1") && doc.HasItem("variable2") && doc.GetFirstItem("Remark").Text.ToLower().Contains(modules.CheckUser().ToLower().ToString()))
        {
            string remark = doc.GetFirstItem("variable0").Text;
            string ticket = doc.GetFirstItem("variable1").Text;
            string workstation = doc.GetFirstItem("variable2").Text;
            notesrow.Text = ticket.ToString().ToUpper();
            notesrow.SubItems.Add(workstation);
            notesrow.SubItems.Add("");
            ListView lv = this.notesDBInfo1.listView1;
            lv.Items.Add(notesrow);
        }
        doc = nview.GetNextDocument(doc);
    }
    //added these because of some other code i read. they dont appear to help me here
    Marshal.ReleaseComObject(nview);
    Marshal.ReleaseComObject(ndb);
    Marshal.ReleaseComObject(ns);

    //the ibm documentation sets the variables to "nothing" because it's VB so i set to null.. still holds the connection.
    ns = null;
    ndb = null;
    nview = null;
    doc = null;
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Dustin
  • 63
  • 7
  • Using Marshal.ReleaseComObject() almost never works. There are a lot more interface references that you don't release because you can't see them getting used. So no, it isn't instantly going to release anything when you're done. Sane thing to do is just keep running, keep doing useful things, the garbage collector will eventually run. Or end your program. If you want to do it on demand then you have to call GC.Collect() + GC.WaitForPendingFinalizers(). Important to do that in the code that calls the method you posted so it still works when you debug. – Hans Passant Nov 25 '15 at 16:30
  • http://stackoverflow.com/a/25135685/17034 – Hans Passant Nov 25 '15 at 16:32
  • I'm actually trying this now Marshal.FinalReleaseComObject(nview); Marshal.FinalReleaseComObject(ndb); Marshal.FinalReleaseComObject(ns); GC.Collect(); GC.WaitForPendingFinalizers(); it when doing it in VS vshost.exe still holds onto names. but I built the exe without vs and it appears to be working. I wont know for a few hours when the session times out or whatever happens. – Dustin Nov 25 '15 at 17:12
  • You ignored the last sentence in my comment. – Hans Passant Nov 25 '15 at 23:59

0 Answers0