6 Replies Latest reply: Jul 20, 2013 3:25 AM by 1010349 RSS

    Memory leak in ODP.NET

    1010349

      Hi.

      I found a memory leak problem in OracleBulkCopy.

      I tried to insert 20000 rows into table in one batch vie oraclebulkcopy.writetoserver.

      using (OracleBulkCopy obc = new OracleBulkCopy(this.c.configDict["ConnectionString"]))

                  {

                      string fileName = parsedValues.Rows[0]["FileName"].ToString();

                      obc.BatchSize = parsedValues.Rows.Count;

                      obc.DestinationTableName = GetTableName(fileName);

                      try

                      {

                          obc.WriteToServer(parsedValues);

                      }

                      catch (OracleException e)

                      {

                          this.l.WriteLog(e.Message);

                        

                      }

                      catch (Exception e)

                      {

                          this.l.WriteLog(e.Message);

                      }

                      finally

                      {

                          parsedValues.Clear();

                          parsedValues.Dispose();

                          obc.Connection.Close();

                          obc.Connection.Dispose();

                          obc.Close();

                          obc.Dispose();

                          GC.Collect();

                          GC.WaitForFullGCComplete();

                      }

      If writetoserver() run without exception - all good, it can work all day long, but if exception was thrown memory leak increases and then it generate a Memory could not be allocated exception.

      Does somebody solve this problem anyhow?

        • 1. Re: Memory leak in ODP.NET
          gdarling - oracle

          What version of ODP.NET are you using?

          What exception are you getting?

          Do you have a small complete testcase we can run here?

           

          I tested the following, with 11203 patch 20 ODP.NET, and the memory usage was stable.  I wasn't sure what error you're introducing so I just introduced an ora-942 "table or view does not exist"

           

          Greg

           

           

           

          using System;
          using System.Data;
          using Oracle.DataAccess.Client;
          
          namespace bulkcopyexceptionleak
          {
              class Program
              {
                  static void Main(string[] args)
                  {
                      DataTable dt = new DataTable();
                      for (int i = 0; i < 100000; i++)
                      {
                          using (OracleBulkCopy obc = new OracleBulkCopy("data source=orcl;user id=scott;password=tiger"))
                          {
                              
                              obc.BatchSize = dt.Rows.Count;
                              obc.DestinationTableName = "invalid_table_name";
                              try
                              {
                                  obc.WriteToServer(dt);
                              }
                              catch (OracleException e)
                              {
                                  //Console.Write(e.Message);
                                  Console.Write(".");
                              }
                              finally
                              {
                                  obc.Connection.Close();
                                  obc.Connection.Dispose();
                                  obc.Close();
                                  obc.Dispose();
                                  GC.Collect();
                                  GC.WaitForFullGCComplete();
                              }
                          }
                      }
                  }
              }
          }
          
          • 2. Re: Memory leak in ODP.NET
            1010349

            Hi. Thanks for the answer.

            I am using latest ODP.NET also 11203 patch 20.

            When the oracle table is locked or unavailable application threw an "Error at recursive SQL level 1" or something that, but it is correct because the table is locked. After aproximately 40 minutes (i thinks is depends on available mamory of the system) it threw an exception "Memory could not be allocated". I also try to find some answers in google but it is nothing.

            Today i tried to use 64 bit Windows server 2008 R2 but the leak also appeared.

             

            Also i Install .net memory profiler and make 2 snapshots: the first was in normal work of the application and the second was int he moment of Exception "Memory coul not be allocated". When i compare this two snapshots i find that there is too much memory used by unmanaged code in ntdll.dll when Oracle.DataAccess calling function Oracle.DataAccess.Client.OpsBC.AllocBufferNode( ref OPOBufferNode*,int,int ).

            Unfortunately i havent any small test, but if you want i can make it =)

            Thanks =)

            • 3. Re: Memory leak in ODP.NET
              gdarling - oracle

              I tried using an actual datatable with 10000 rows, and locked the table so the exception I got was ora-604/ora-54, but still was unable to see an increase in memory.

               

              I'd recommend opening a SR with support so we can look into this further.

               

              Greg

              • 4. Re: Memory leak in ODP.NET
                Manuel P

                You should try to update to patch 22. According to its description text the following bug was fixed in it:

                Bug 10084752 (MEMORY LEAK USING ORACLEBULKCOPY)

                • 5. Re: Memory leak in ODP.NET
                  1010349

                  I can't find it anywhere. Could you help me to find this version?

                  • 6. Re: Memory leak in ODP.NET
                    1010349

                    I find, metalink now in offline. Thanks.