Ejemplo n.º 1
0
    def testPassedObjectGetsCleanedUp(self):
        import platform
        if platform.python_implementation() == 'PyPy':
            raise common.unittest.SkipTest(
                'PyPy memory model does not pass test')

        h = JClass('jpype.attr.Test1')()
        block_size = 1024 * 1024 * 10

        def allocate_then_free():
            byte_buffer = jpype.JClass('java.nio.ByteBuffer')
            inst = byte_buffer.allocate(1024 * 1024 * 100)
            # passing the object back to java seems to stop it being collected
            result = h.callWithSomething(inst)

        rt = JClass('java.lang.Runtime').getRuntime()
        free = rt.freeMemory()
        for x in range(0, 10 * free // block_size):
            allocate_then_free()