I have read it many times that lazy evaluation in Haskell may sometimes lead to space leaks. What kind of code can lead to space leaks? How to detect them? And what precautions can be taken on part of a programmer to avoid them?
Space leaks in Haskell
3.3k views Asked by missingfaktor At
2
There are 2 answers
0
afkbowflexin
On
I've run into this problem when doing recursion over large data structures. The built up thunks get to be too much and then you get a space leak.
In Haskell, you need to be constantly aware of the possibility of running into a space leak. Since iteration doesn't exist, basically any recursive function has the potential to generate a space leak.
To avoid this problem, memoize recursive functions, or rewrite them tail-recursively.
Related Questions in HASKELL
- How can I determine if a video has just finished using expo.video? ReactNative/Expo.io
- Unknown named Module, using component will receive props to update an image
- Video is still playing when i navigate to another layout
- Error running adb: Error running app. Error: Activity not started, unable to resolve Intent
- Video playlist issue (when one video ends, the next video plays beginning from the length of previous vid) Expo/React Native
- Why is my function being called infinitely? (react-native/expo)
- Are silent Expo push-notifications possible?
- Change navigation bar color
- Set up different language for iOS app using react-native and expo
- Using Animated.Flatlist and Animated.ScrollView to animate an Animated.View is not smooth
Related Questions in FUNCTIONAL-PROGRAMMING
- How can I determine if a video has just finished using expo.video? ReactNative/Expo.io
- Unknown named Module, using component will receive props to update an image
- Video is still playing when i navigate to another layout
- Error running adb: Error running app. Error: Activity not started, unable to resolve Intent
- Video playlist issue (when one video ends, the next video plays beginning from the length of previous vid) Expo/React Native
- Why is my function being called infinitely? (react-native/expo)
- Are silent Expo push-notifications possible?
- Change navigation bar color
- Set up different language for iOS app using react-native and expo
- Using Animated.Flatlist and Animated.ScrollView to animate an Animated.View is not smooth
Related Questions in LAZY-EVALUATION
- How can I determine if a video has just finished using expo.video? ReactNative/Expo.io
- Unknown named Module, using component will receive props to update an image
- Video is still playing when i navigate to another layout
- Error running adb: Error running app. Error: Activity not started, unable to resolve Intent
- Video playlist issue (when one video ends, the next video plays beginning from the length of previous vid) Expo/React Native
- Why is my function being called infinitely? (react-native/expo)
- Are silent Expo push-notifications possible?
- Change navigation bar color
- Set up different language for iOS app using react-native and expo
- Using Animated.Flatlist and Animated.ScrollView to animate an Animated.View is not smooth
Related Questions in SPACE-LEAK
- How can I determine if a video has just finished using expo.video? ReactNative/Expo.io
- Unknown named Module, using component will receive props to update an image
- Video is still playing when i navigate to another layout
- Error running adb: Error running app. Error: Activity not started, unable to resolve Intent
- Video playlist issue (when one video ends, the next video plays beginning from the length of previous vid) Expo/React Native
- Why is my function being called infinitely? (react-native/expo)
- Are silent Expo push-notifications possible?
- Change navigation bar color
- Set up different language for iOS app using react-native and expo
- Using Animated.Flatlist and Animated.ScrollView to animate an Animated.View is not smooth
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
You will get probably many answeres, this is the one, I have encountered when trying to do some 'real-world' application. I was using multithreading and some MVars to pass data around (MVar is something like locked shared memory). My typical pattern was:
And then, just sometimes, when a proper condition happened I did something like:
The problem is that the content of mvar was essentially (0 + 1 + 1 + 1 + ....)...which was quite intensive for numbers like 100k... This type of problem was quite pervasive in my code; unfortunately for multithreading applications it's very easy to get into such problems.
Detecting...what I did was starting haskell in the mode that produces data regarding memory consumption, starting and stopping different threads and looking if memory footprint is stable or not...
Anotomy of a thunk leak (with instructions how to debug it)
An example: Thunk memory leak as a result of map function