# Using Juce with cocoa app

**URL:** <https://forum.juce.com/t/using-juce-with-cocoa-app/7294>\
**Category:** MacOSX and iOS\
**Created:** [August 12, 2011, 3:51pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294 "2011-08-12T15:51:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [August 12, 2011, 3:51pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/1 "2011-08-12T15:51:01Z")

</div>

Hi,

I am testing if it is possible to use the non-gui classes of JUCE within a standard iphone app that uses cocoa for its user interface. I created a view based application and added initialiseJuce\_GUI(); to the app delegates

- (BOOL)application:(UIApplication \*)application didFinishLaunchingWithOptions:(NSDictionary \*)launchOptions  
method.

To properly shutdown juce when the app quits I added shutdownJuce\_GUI(); to the app delegates

- (void)applicationWillTerminate:(UIApplication \*)application  
method.

When I quit the simulator I get the following assertion:

\*\*\* Leaked objects detected: 1 instance(s) of class HeapBlock  
JUCE Assertion failure in /Users/patrick/Documents/development/libs/juce/Builds/iOS/…/…/src/native/mac/…/…/core/…/memory/juce\_LeakedObjectDetector.h, line 95

Did I miss somenthing? Do I need to release something else to properly shutdown an application that uses Juce?

Patrick

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 12, 2011, 3:56pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/2 "2011-08-12T15:56:04Z")

</div>

Not sure how you’d manage to leak a HeapBlock… It’s perhaps part of a larger structure that you’re leaking?

---

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [August 12, 2011, 6:00pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/3 "2011-08-12T18:00:07Z")

</div>

Sure. I would also except a problem in my code normally. But for this test I am not making any calls to Juce except initialiseJuce\_GUI() and shutdownJuce\_GUI(). Just starting, then stopping the app triggers the assertion.

Patrick

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 12, 2011, 6:04pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/4 "2011-08-12T18:04:36Z")

</div>

Well, nothing in the library will allocate a HeapBlocks on the heap, or create a static one, so I’ve no idea how that could happen. Surely there must be more leaks than just the one, because the HeapBlock must be a member of something else?

---

<div class="post-metadata">

**Author:** ![Bruce\_Wheaton](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Bruce\_Wheaton](https://forum.juce.com/u/Bruce_Wheaton)\
**Post date:** [August 12, 2011, 6:21pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/5 "2011-08-12T18:21:10Z")

</div>

Not creating an AudioDeviceManager, are you? Do you have any static members which juce may be creating for you?

Bruce

---

<div class="post-metadata">

**Author:** ![jaydee](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jaydee](https://forum.juce.com/u/jaydee)\
**Post date:** [August 12, 2011, 7:16pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/6 "2011-08-12T19:16:01Z")

</div>

“Quit the simulator” or press the home button on the simulator?

Put a breakpoint on applicationWillTerminate:

(I ran into something like this last year, and I remember quitting the simulator being different than hitting the home button[quitting didn’t call app terminate])

---

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [August 12, 2011, 9:53pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/7 "2011-08-12T21:53:11Z")

</div>

> Put a breakpoint on applicationWillTerminate:

yup, the breakpoint it is never hit, not with the home button and not with quitting the simulator. It seems task management is not deterministic.

My final test was to let Introjucer generate a default project, using static linking. After compiling, starting the app from Xcode and quitting the simulator the same assertion is triggered.

I am working on Lion, using Xcode 4.1.

Well, if the way I am initializing and shutting down Juce is correct and this assertion is not a sign of a fundamental problem I’m happy to simply press the “Stop debugging” button in Xcode instead of quitting the simulator to get around that assertion.

Patrick

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 12, 2011, 9:58pm UTC](https://forum.juce.com/t/using-juce-with-cocoa-app/7294/8 "2011-08-12T21:58:39Z")

</div>

TBH I wouldn’t worry too much about the “leak”, as it’s probably just a HeapBlock inside a static object somewhere. The leak detector can report false positives sometimes, when you have static objects that get deleted after the leak-detector’s own statics. I’ll have a look at it next time I’m doing some ios stuff anyway.
