• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Page Information

    Loading...
  1. Dashboard
  2. Undefined Space
  3. Port: MacOSX
  4. ObjC Memory Management and JNI

Page History

Versions Compared

Old Version 8

changes.mady.by.user Mike Swingler

Saved on Sep 21, 2011

compared with

New Version 9

changes.mady.by.user Mike Swingler

Saved on Sep 29, 2011

  • Previous Change: Difference between versions 7 and 8
  • Next Change: Difference between versions 9 and 10
  • View Page History

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Adding more caveats ObjC-GC and structs

...

  • If you need to pass a Java object through native (like to the main AppKit thread, or inside of an NSArray), use JNFJObjectWrapper or JNFJObjectWeakWrapper
    • It handles all the details of managing a JNI global ref in a native ObjC object in both RR and GC modes
  • If you have a JNIEnv when you are done with the JNFJObjectWrapper, pre-clear the reference
    • It is more efficient than the wrapper's -dealloc, which may have to connect the current thread to the JVM (possibly a ObjC-GC collector thread), just for the purposes of deleting the ref.

Don't put ObjC objects into C-structs

  • The ObjC garbage collector can't find objects that have been stuffed into C arrays and structs
  • If you must use a struct to hold onto a ObjC object (like some pieces of the graphics code currently does), you need to pin the ObjC using CFRetain(), just like if you were going to push it up into the JVM heap.
    • Be sure to CFRelease() any AppKit objects on the main AppKit thread, so their -dealloc methods will be called on the right thread!
Overview
Content Tools
ThemeBuilder

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.23
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 304, "requestCorrelationId": "a61bc7adaca120c6"}