I tried to use Math::GSL::Min and here is a problem with gsl_min_fminimizer_iterate() mentioned in KNOWN_BUGS.
This problem arises from typemap for gsl_function. It assumes that callback executes when we pass it to some gsl_* function.
But in Math::GSL::Min (and at least in Math::GSL::Root) we have a deferred callback execution: some function like gsl_min_fminimizer_set_with_values()takes callback as a param and after this some function like gsl_min_fminimizer_iterate() uses this callback.
I made a primitive patch for this typemap ( https://gist.github.com/1089862 ). It makes 2 things:
1) we dynamically create a stuct gsl_function_perl * pointer
2) we remove typemap(freearg) gsl_function * because our pointers must live after.
Commented tests in t/Min.t and t/Roots.t works after this patch (and others too).
stuct gsl_function_perl *
typemap(freearg) gsl_function *
But after this we have 2 problems with memory:
1) we should check that such function as gsl_min_fminimizer_free() or undef'ing minimizer really frees memory. If it doesn't we should fix it somehow.
2) if we use some gsl_* functions with immediate callback execution (for example gsl_integration_qagiu()) we should call some *_free() function anyway.
I will explore this problem deeply (my knowledge of XS isn't good). But comment please if you have any ideas.
If you turn that gist into a branch, I will test it out on my machine.
In general, if your patch makes more tests pass, then I am all for it.
To help with memory leaks, we should probably add an author test that runs our test suite under Valgrind. I think there are some CPAN modules that help with that.
#28 is a pull request that solves this problem for a case when we have gsl_function as input parameter and make a deferred callback execution (exactly two cases: Math::GSL::Roots and Math::GSL::Min).
Sorry for additional issue ( #28 ) created together with pull request.
For another cases (such as a gsl_function_fdf) we can make separate isssues and resolve these issues relying on this issue.
I have added comments for the pull request.
Sorry, actually I placed comments in my commit, not in the pull request:
Fixed in #28.