Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell memory management under IOS 5

I want to embed Haskell engine into IOS 5 project as a C library - to run Haskell code inside the IOS app. So I have several questions:

  1. Is there any known memory management problem that Haskell reveals under ARC?
  2. How could I ensure that Haskell did not interfere with IOS memory management?
  3. What may be an effective strategy for dealing with these issues?
like image 926
BorisV Avatar asked Mar 01 '12 20:03

BorisV


People also ask

How does Haskell manage memory?

Haskell computations produce a lot of memory garbage - much more than conventional imperative languages. It's because data are immutable so the only way to store every next operation's result is to create new values. In particular, every iteration of a recursive computation creates a new value.

Why does Haskell need garbage collection?

The answer is that a GC is required under the hood to reclaim the heap objects that the language MUST create. For example. A pure function needs to create heap objects because in some cases it has to return them. That means that they can't be allocated on the stack.

Does Haskell use garbage collection?

The Haskell runtime system employs a generational garbage collector (GC) with two generations 2. Generations are numbered starting with the youngest generation at zero.


1 Answers

ARC is strictly a compile-time code generation process that relates to Objective-C code. ARC basically means "inserting retain, release and autorelease statements into the source* at compilation time so the programmer doesn't have to".

Consequently, ARC won't do anything to non-Objective C code (i.e. regular C libraries) and has no runtime behaviour** that might interfere with the garbage collection behaviour of the Haskell engine.

*That's not actually how ARC works, it generates optimised assembly code, not source code, but as an analogy it's a good description of how it works.

**Strictly speaking, it's not true that ARC has no runtime behaviour, as there is the weak pointer management that happens at runtime, but again that applies only to Objective-C objects and won't do anything to Haskell code.

like image 98
Nick Lockwood Avatar answered Oct 13 '22 00:10

Nick Lockwood