[jira] (JMOCK-262) Memory is getting leaked when using Action calls that are repeated many times

View: New views
5 Messages — Rating Filter:   Alert me  

[jira] (JMOCK-262) Memory is getting leaked when using Action calls that are repeated many times

by JIRA jira@codehaus.org :: Rate this Message:

| View Threaded | Show Only this Message

Matthew Hussey created JMOCK-262:
------------------------------------

             Summary: Memory is getting leaked when using Action calls that are repeated many times
                 Key: JMOCK-262
                 URL: https://jira.codehaus.org/browse/JMOCK-262
             Project: jMock
          Issue Type: Bug
          Components: JMock 2.x.x Library
    Affects Versions: 2.5.1
         Environment: Windows 7, Eclipse. Java 1.7, JMock 2.6.0RC2 and JMock2.5.1
            Reporter: Matthew Hussey


I was using mock objects to mock functions that are called many times so I could compare the functionality of two classes I had developed but kept getting OutOfMemory: GC Overhead Limit Exceeded or just OutOfMemory. I was using custom actions and after doing a heap dump I noticed that there were millions of Invocation instances along with the instances of the parameters they were holding. I've not prepared a version that doesn't use custom actions to prove the problem.

I am well aware that this code isn't how mocks are supposed to be used but I just wanted to invoke multiple mocked Action calls to highlight the issue. Anyway, commenting out the CONCRETE section causes an OutOfMemory exception, while commenting out the MOCK section allows the function to run perfectly, but isn't using JMock.

I am running using -Xmx128m to try and force the problem to occur earlier.

While typing this, I think I'm coming to the conclusion that this is a side-effect of holding onto the previous invocations so that the trace can contain all the invocations if there is any call that breaks the expectations. This means that the memory leak is by design rather than a bug but I think it's best to report it anyway.

I guess it would be nice to be able to disable the storing of the invocations if all that is needed is the mock functionality and asserts.

I'm kind of babbling now so I'll stop now.

/**
 *
 */
package jMockMemoryTest;

import org.jmock.Expectations;
import org.jmock.Mockery;

/**
 * @author matt
 *
 */
public class JMockMemoryTest {
       
        private interface SomethingMocked {
                boolean isItEven(int num);
        }
       
        private final SomethingMocked sm;
       
        public JMockMemoryTest(SomethingMocked sm) {
                this.sm = sm;
        }
       
        int sumOfAllEvens(int limit) {
                int total = 0;
                for(int i = 0; i != limit; ++i) {
                        if(sm.isItEven(i)) {
                                ++total;
                        }
                }
               
                return total;
        }
       
        private static class SomethingConcrete implements SomethingMocked {

                @Override
                public boolean isItEven(int num) {
                        return true;
                }
               
        }

        /**
         * @param args
         */
        public static void main(String[] args) {
                Mockery context = new Mockery();
               
                // CONCRETE BEGIN
                /*
                final SomethingMocked mock = new SomethingConcrete();
                */
                // CONCRETE END
               
                // MOCK BEGIN
                final SomethingMocked mock = context.mock(SomethingMocked.class);
               
                context.checking(new Expectations() {
                        {
                                allowing(mock).isItEven(with(any(Integer.class))); will(returnValue(true));
                        }
                });
                // MOCK END
               
                JMockMemoryTest jmmt = new JMockMemoryTest(mock);
               
                for(int limit = 0; limit != 100000; ++limit) {
                        System.out.println(jmmt.sumOfAllEvens(limit));
                }
        }

}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] (JMOCK-262) Memory is getting leaked when using Action calls that are repeated many times

by JIRA jira@codehaus.org :: Rate this Message:

| View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Steve Freeman commented on Bug JMOCK-262

An interesting use of the framework I fear this has to count as a won't fix, because much of the motivation of jMock is to consider how objects interact and provide a useful message when there's a problem. You might want to consider poking around a level below the Expectations() object to see if you could use the pieces to assemble something closer to what you need. It shouldn't be too hard.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

[jira] (JMOCK-262) Memory is getting leaked when using Action calls that are repeated many times

by JIRA jira@codehaus.org :: Rate this Message:

| View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Change By: Steve Freeman (21/May/12 4:46 AM)
Assignee: Steve Freeman
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

[jira] (JMOCK-262) Memory is getting leaked when using Action calls that are repeated many times

by JIRA jira@codehaus.org :: Rate this Message:

| View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Steve Freeman resolved Bug JMOCK-262 as Won't Fix

See my comment on the issue.

Change By: Steve Freeman (21/May/12 4:46 AM)
Resolution: Won't Fix
Fix Version/s: Chore (ASAP)
Status: Open Resolved
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

[jira] (JMOCK-262) Memory is getting leaked when using Action calls that are repeated many times

by JIRA jira@codehaus.org :: Rate this Message:

| View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Matthew Hussey commented on Bug JMOCK-262

Hi,

Yeah I imagined that would be the case.

Just to explain my "interesting" use of JMock. I'd written an implementation of an interface in the past and had written a new, more optimised, version. I wanted to run a load of calls through each of them to check that they worked the same. Rather than injecting real supporting classes, I thought I'd just mock the functions required. The problem is that the functions in the implemented classes loop many times to hunt for a result and hence called the mocks many times and caused the problem.

I think this issue could happen in reality if a function in the tested class had a for loop that was calling a function of a supporting class and summing the results for return. I think in most cases the developer could fix this by reducing the number of items looped through in the for loop for testing purposes. I've already thought of a way to refactor what I am doing to avoid this problem and the code may be better for it.

Anyway, I expected this to be Won't Fix. I'd have done the same

Thanks

Matt

PS. Great tool. Gradually getting people at work to consider using it...

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email