Skip to content

Instantly share code, notes, and snippets.

@dalinaum
Created December 26, 2016 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalinaum/2d84d28d1ab497a6ca86dd12d653fbee to your computer and use it in GitHub Desktop.
Save dalinaum/2d84d28d1ab497a6ca86dd12d653fbee to your computer and use it in GitHub Desktop.

init(Context)

  1. BaseRealm.applicationContext이 비어 있는지 확인
  2. RealmCore.loadLibrary를 호출. ReLinker.loadLibrary를 이용해서 적절한 라이브러리를 불러온다. 이 메서드는 단 한번만 여러번 호출해도 라이브러리를 한번만 불러오도록 되어 있다.
  3. RealmConfiguration.Builder(context).build()를 호출하여 defaultConfiguration을 생성.
  4. BaseRealm.applicationContext을 context.getApplicationContext();으로 설정
  5. SharedRealm.initialize를 호출한다. 이는 한번만 수행되도록 구성되어 있고 디렉토리가 없다면 생성해서 naitveInit을 호출하고 이는 realm::set_temporary_directory를 다시 호출하여 정적 변수 temporary_directory를 설정하며 다시 SharedRealm.initialize는 SharedRealm.temporaryDirectory로 해당 디렉터리를 지정한다.

getDefaultInstance()

getDefaultInstance는 RealmCache.createRealmOrGetFromCache를 호출한다. RealmCache.createRealmOrGetFromCache은 cachesMap에서 설정의 경로에 맞는 RealmCache 인스턴스가 존재하는지 확인한다. 캐쉬가 없다면 RealmCache 인스턴스를 만들고 설정을 configuration에 넣고 EnumMap<RealmCacheType, RefAndCount>으로 refAndCountMap 인스턴스를 만든다. RealmCacheType은 TYPED_REALM, DYNAMIC_REALM 인지의 여부를 지정하며 RefAndCount는 해당 스레드에서의 BaseRealm과 카운트를 체크한다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment