Skip to content

Memory Leak - Again #121

@kevingy

Description

@kevingy

As indicated in Issue #120, memory leaks have been reported by iEmiya. Leaks can be reproduced with this test:

A simple test for memory leaks.

        [Test]
        public void MemoryLeak()
        {
            // look : exception
            long? useTotalMemory = null;
            var task = System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                long threadId = 1;
                while (true)
                {
                    long totalMemory = GC.GetTotalMemory(false);
                    Trace.WriteLine(string.Format("Use total memory: {0:#,##0} byte(s)", totalMemory));
                    if (threadId % 20 == 0)
                    {
                        if (!useTotalMemory.HasValue) useTotalMemory = totalMemory;
                        else
                        {
                            if (totalMemory > useTotalMemory) throw new ApplicationException("Memory leak in 'SimpleBrowser'");
                            break; // Ok
                        }
                    }


                    try
                    {
                        threadId++;
                        Browser b1 = new Browser(Helper.GetFramesMock());
                        b1.Navigate("http://localhost/");
                        if (threadId % 2 == 0) throw new ApplicationException();
                        b1.Close();

                        GC.WaitForPendingFinalizers();
                        GC.Collect();
                    }
                    catch (Exception e)
                    {
                        Trace.Fail("Failed to navigate");
                    }
                }
            });

            task.Wait();
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions