Question

After changing the data structure from diffarray to vector the memory blows up (grows infinitely) during one of the QuickCheck tests.

The code is hosted at GitHub. The dev branch contains the ill code and the master one runs well. Apart from minor changes the only commit which could have any effect on that is this one. In order to run the QuickCheck routines one should run the executable tester. It seems that small length vectors don't crash the program, but when it gets longer the program slows down and finally blows the memory up. Another thing that intrigues me is the fact that I'm having a similar problem in an other of my libraries while rendering XML files. For small files (<400k) it runs slow but with no crash and for larger files the memory blows up. The Data.Vector is also involved in that library. I have the intuition these problems are related.

Edit: I've finally isolated the part of my code that reproduce the memory leak and put it into a single file which can be found here. Now I'm using IArray that behaves as well as DiffArray. To alternate between IArray and Vector one have to modify the lines 49, 93 and 101.

Was it helpful?

Solution

Solved Actually the problem was on the generation of vectors by QuickCheck. The original Arbitrary instance for Vector was the following:

instance (Arbitrary a) => Arbitrary (Vector a) where
  arbitrary   = liftM2 Vec.generate arbitrary arbitrary

which compiles but gives a memory leak. The problem can be solved if the vectors are generated from lists. Like this:

instance (Arbitrary a) => Arbitrary (Vector a) where
  arbitrary = Vec.fromList <$> arbitrary

I still don't know way what was the reason of such a bug....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top