https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • j

    JoakimForslund

    08/26/2019, 8:49 AM
    Trying to send back a jstring from kotlin native jni-bridge, is there a way to create/convert a kotlin string to a jstring? Example I have now:
    @CName("Java_com_example_project_createString")
    fun createString(env: kotlinx.cinterop.CPointer<JNIEnvVar>, instance: jobject):jstring?{
        val jniNativeInterface: JNINativeInterface = env.pointed.pointed!!
        val fNewStringUTF = jniNativeInterface.NewStringUTF!!
        val result = fNewStringUTF(env, "A test")
        return result
    }
    Where the 'A test' part wont work, because of it not being a jstring
    s
    m
    • 3
    • 5
  • s

    salomonbrys

    08/26/2019, 1:32 PM
    Here's a follow-up to the thread about memory-model & my proposal for const classes to reduce multiplatform friction: https://medium.com/@timelzayus/designing-a-kotlin-memory-safe-mode-c76c06317c3e
    🍿 5
    💯 1
    v
    • 2
    • 1
  • s

    spierce7

    08/26/2019, 4:39 PM
    If you are in swift trying to access a Kotlin/native extension function - what does that look like? i.e. for JVM it’s expressed as a static utility / helper class.
    b
    • 2
    • 2
  • n

    napperley

    08/27/2019, 2:34 AM
    Added some additional definitions in the udev.def file, and encountered a linking error, where it isn't clear what is causing the error:
    Task :cinteropUdevLinux FAILED
    Exception in thread "main" java.lang.Error: /tmp/tmp360311134357443805.c:26:3: error: expected expression
    b
    m
    • 3
    • 13
  • j

    JoakimForslund

    08/27/2019, 9:14 AM
    I'm somewhat confused. I converted a c-function, which ends up being this in kotlin:
    public fun AES_CBC_encrypt_buffer(output: kotlinx.cinterop.CValuesRef<platform.posix.uint8_tVar /* = kotlinx.cinterop.UByteVarOf<platform.posix.uint8_t /* = kotlin.UByte */> */>?, input: kotlinx.cinterop.CValuesRef<platform.posix.uint8_tVar /* = kotlinx.cinterop.UByteVarOf<platform.posix.uint8_t /* = kotlin.UByte */> */>?, length: platform.posix.uint32_t /* = kotlin.UInt */, key: kotlinx.cinterop.CValuesRef<platform.posix.uint8_tVar /* = kotlinx.cinterop.UByteVarOf<platform.posix.uint8_t /* = kotlin.UByte */> */>?, iv: kotlinx.cinterop.CValuesRef<platform.posix.uint8_tVar /* = kotlinx.cinterop.UByteVarOf<platform.posix.uint8_t /* = kotlin.UByte */> */>?): kotlin.Unit { /* compiled code */ }
    I'm trying to use it with the following setup: https://gist.github.com/Syrou/52db691f91928cb6aad6bcfd84bf5cff 1. Am I wrong in trying to use toCValues() method to translate the uByteArrays into what is specified in the method argument? 2. Am I using the buffer pinning wrong? Because each time I run this code I end up with a new result. This might be an error in the c-lib to start with, but I'm currently investigating if my implementation of the native code is wrong.
    a
    • 2
    • 4
  • n

    napperley

    08/27/2019, 9:30 AM
    With the libusb library the
    libusb_get_device_list
    function takes a list (parameter) however the list is a container for
    libusb_device
    , which is a opaque pointer. Is there a way to allocate a opaque pointer? Below is the function's mapping:
    public fun libusb_get_device_list(ctx: kotlinx.cinterop.CValuesRef<cnames.structs.libusb_context>?, list: kotlinx.cinterop.CValuesRef<kotlinx.cinterop.CPointerVar<kotlinx.cinterop.CPointerVar<cnames.structs.libusb_device> /* = kotlinx.cinterop.CPointerVarOf<kotlinx.cinterop.CPointer<cnames.structs.libusb_device>> */> /* = kotlinx.cinterop.CPointerVarOf<kotlinx.cinterop.CPointer<kotlinx.cinterop.CPointerVarOf<kotlinx.cinterop.CPointer<cnames.structs.libusb_device>>>> */>?): platform.posix.ssize_t /* = kotlin.Long */ { /* compiled code */ }
    s
    a
    • 3
    • 9
  • j

    Jonas Bark

    08/28/2019, 3:00 PM
    Does kotlin-native (iOS) has problems with dashes in pod dependencies? e.g.
    cocoapods { ... pod("SignalR-ObjC") }
    fails with
    > Task :redacted:cinteropSignalR-ObjCIosX64 FAILED
    
    Exception in thread "main" java.lang.Error: /var/folders/5w/vjnd8mf17jlclpg31lfzlk0h0000gn/T/tmp3333782877975402348.m:1:9: fatal error: module 'SignalR' not found
    a
    • 2
    • 2
  • n

    napperley

    08/29/2019, 3:50 AM
    When using a C library (via Kotlin Native) with Kotlin Coroutines would it be better to go with a synchronous API (eg http://libusb.sourceforge.net/api-1.0/group__libusb__syncio.html ), or a asynchronous API (eg http://libusb.sourceforge.net/api-1.0/group__libusb__asyncio.html )?
    b
    • 2
    • 1
  • t

    tateisu

    08/29/2019, 4:06 AM
    Is there .toKString() with charset specification? I'm using Mingw, strerror() charset is locale dependent and setlocale() don't allow UTF-8 codepage.
    o
    • 2
    • 1
  • g

    Glen

    08/30/2019, 10:42 PM
    Hello everyone. I need to use a static C library, written by a friend of mine. How do I include it in a Kotlin/Native project, using CInterop? And also, how do I use the library from there in an android client?
    k
    a
    • 3
    • 14
  • a

    Arkadii Ivanov

    08/31/2019, 2:11 AM
    Just in case anyone stuck with Gradle task
    linkDebugTestLinuxX64
    failing with error message
    e: Unable to compile C bridges
    on Ubuntu: you have to install
    libtinfo5
    and perhaps
    libtinfo-dev
    packages. Wasted 1h on this problem 😞
    👍 1
    m
    s
    • 3
    • 7
  • n

    napperley

    08/31/2019, 8:46 AM
    Is there a straightforward way to convert
    CArrayPointer<UByteVar>
    to a String?
    d
    b
    o
    • 4
    • 5
  • a

    Akram

    08/31/2019, 7:21 PM
    hello everyone , i'm just starting with kotlin native and want to understand how kotlin native concurrency and memory model works, so i need some tutorials or blogs thanks in advance
    d
    k
    • 3
    • 3
  • m

    molikuner

    08/31/2019, 10:12 PM
    Could anyone get wasm32 compiling with Kotlin 1.3.50 on Linux? Just getting a JVM crash on
    linkDebugExecutableWasm32
    . Kotlin 1.3.41 is working fine.
    d
    • 2
    • 6
  • t

    Tobi

    09/02/2019, 6:29 AM
    Hey folks, is there a way to interop with a cocoapods swift dependency from kotlin/native in a multiplatform project?
    j
    s
    j
    • 4
    • 6
  • v

    Vincent Chen

    09/02/2019, 3:17 PM
    Hi everyone, I want to generate .so file for Android, only androidNativeArm64 / 32, how to generate x86 / x86_64 for android? Can i use linux???
    :yes: 1
    d
    m
    • 3
    • 12
  • r

    ribesg

    09/03/2019, 10:07 AM
    Just updating from 1.3.41 to 1.3.50, something broke:
    > Task :...:bugsnag:cinteropBugsnagIos
    Exception in thread "main" java.lang.IllegalStateException: clang_parseTranslationUnit2 failed with CXError_ASTReadError;
    sourceFile = /var/folders/6l/fxc2038542q1pfrjs6br35pw0000gn/T/tmp447253035168640890tmp5260654680929876680.m
    arguments = -framework Bugsnag -fmodules -isystem /Users/me/.konan/dependencies/clang-llvm-6.0.1-darwin-macos/lib/clang/6.0.1/include -B/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -fno-stack-protector -stdlib=libc++ -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk -miphoneos-version-min=9.0.0 -I/Users/me/IdeaProjects/.../bugsnag/Carthage/Build/iOS/Bugsnag.framework/Headers -fobjc-arc -include-pch /var/folders/6l/fxc2038542q1pfrjs6br35pw0000gn/T/tmp1938929871985065456.pch -Werror=implicit-function-declaration -ferror-limit=0
    	at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.parseTranslationUnit(Utils.kt:99)
    	at org.jetbrains.kotlin.native.interop.indexer.MacroConstantsKt.expandMacros(MacroConstants.kt:66)
    	at org.jetbrains.kotlin.native.interop.indexer.MacroConstantsKt.findMacros(MacroConstants.kt:34)
    	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:999)
    	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:952)
    	at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:91)
    	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:222)
    	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:38)
    	at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:69)
    	at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:18)
    s
    • 2
    • 4
  • c

    Cyrille QUÉMIN

    09/03/2019, 12:33 PM
    hey there, I have 2 mpp modules A and B. B is using A as a dependency. I produced FAT frameworks from both of them, and include both framework in my iOS app. Everything is good so far. The problem is I have a type in module A Type1 which is used in module 2. But in my ios App if I try to use them together I have an incompatibility error where A.Type1 is said to be incompatible with B.Type1. Whereas they are supposed to be the exactly the same. How can I solve that?
    r
    • 2
    • 4
  • d

    Denis Shurygin

    09/03/2019, 12:50 PM
    NSBundle.localizedStringForKey
    doesn't work properly in pair with
    NSString.localizedStringWithFormat
    . Looks like
    NSString
    losing some metadata during conversion into Kotlin
    String
    . Here is example on Kotlin:
    import platform.Foundation.NSBundle
    import platform.Foundation.NSString
    import platform.Foundation.localizedStringWithFormat
    
    class TestClass(private val bundle: NSBundle) {
        fun localizedStringWithFormat(string: String): String {
            return NSString.localizedStringWithFormat(
                    this.bundle.localizedStringForKey(string, "", "Localizable"), 5)
        }
    }
    Here is the code in swift:
    let testClass = TestClass(bundle: Bundle.main)
    let testString = "screen_main_plural_string"
    let nativeStr = Bundle.main.localizedString(forKey: testString, value: "", table: "Localizable") as NSString
    
    NSLog("swift: %@", NSString.localizedStringWithFormat(nativeStr, 5))
    NSLog("kotlin: %@", testClass.localizedStringWithFormat(string: testString))
    Output logs: swift: Plural: 5 apples kotlin: %#@value@
    o
    s
    • 3
    • 4
  • a

    Arkadii Ivanov

    09/03/2019, 11:29 PM
    FreezableAtomicReference was introduced in Kotlin 1.3.40 and according to its release notes (https://blog.jetbrains.com/kotlin/2019/06/kotlin-1-3-40-released/) it was considered as experimental. No changes were made since its initial implementation. What is the status of it? Are there any known issues? Thanks!
    a
    • 2
    • 1
  • c

    Cyrille QUÉMIN

    09/04/2019, 9:55 AM
    Hey guys, I am building iOS fat framework and everything seems to be working fine on my iOS app. However I have this warning in the build logs:
    w: Interop library /pathToUser/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-io-iosarm64/0.1.14/1ece4fc59ccddcacf23bb04589c7c0f39a94b787/kotlinx-io-cinterop-sockets can't be exported with -Xexport-library
    . Will I experience runtime crashes ? what does it mean exactly for the framework produced ?
    k
    s
    • 3
    • 19
  • g

    galex

    09/04/2019, 1:00 PM
    Hello, do Kotlin enums become real ObjC enums (which are objects after all) or are they like real enums (two values share the same memory instance?
    k
    b
    s
    • 4
    • 8
  • g

    galex

    09/04/2019, 1:15 PM
    And what about nullability in Kotlin, does it translate correctly when used in Swift through ObjC?
    j
    k
    • 3
    • 5
  • s

    serebit

    09/04/2019, 2:42 PM
    The new plugin for debugging K/N in IntelliJ seems to be corrupting my multiplatform projects... If I have it installed and activated, it changes the type of my modules to KONAN_NATIVE, which the normal Kotlin plugin doesn't like, and thus refuses to load.
    k
    a
    • 3
    • 2
  • v

    Vincent Chen

    09/04/2019, 5:53 PM
    Hi, in my Kotlin/native project
    .....
    var outputLength = cValuesOf(0)
    ......
    val outputBA = outputData.readBytes(outputLength convert int)
    How to Convert outputLength to Int Thanks
    d
    c
    • 3
    • 3
  • n

    napperley

    09/04/2019, 9:21 PM
    Is there some consideration being made about including wrappers to cover some common C Macros, which are in the bundled C libraries (varies by target)?
    s
    • 2
    • 6
  • v

    Vincent Chen

    09/05/2019, 3:57 AM
    hi, I write enum in my commonMain at K/N project, then build .so for Android. Now how can I use this enum ?? thanks~
    m
    o
    g
    • 4
    • 11
  • j

    Justin

    09/05/2019, 8:17 PM
    Trying to get a list of devs/companies working with KMP going here - feel free to add to the list! https://twitter.com/justinmkaufman/status/1169650267135991808?s=21
    s
    m
    • 3
    • 9
  • v

    Vincent Chen

    09/06/2019, 8:21 AM
    Hi, Is it possible to get context at androidNativeArm64 ??? Because I Must Build Library include .so for Android(can’t use androidMain) + .framework for iOS Ex: getPackageName…. I think it is no. Then some ways to do this? Thanks
    s
    • 2
    • 1
  • s

    Sam Schilling

    09/06/2019, 4:38 PM
    Has anyone else experienced issues with NSObjects not being deallocated properly? I have a function that is called in a loop which allocates an NSObject (NSProcessInfo) but it never gets deallocated My loop runs for 150 ms and during that time application memory usage typically rises by ~50 MB, and when profiling I see it is because there are thousands of NSProcessInfo objects that never get deallocated (each one is only 4 KB)
    fun elapsedRealtime() = (NSProcessInfo().systemUptime * 1_000)
    
    val startTime = elapsedRealtime()
    var currentTime = startTime
    while (currentTime - startTime < 150) {
        currentTime = elapsedRealTime()
    }
    I would think NSProcessInfo objects should automatically be deallocated each time
    elapsedRealtime
    completes since the reference count would be 0, but I am unsure how Kotlin’s GC interacts with Swift/Objective-C’s ARC If I change the loop to run for 25 seconds for example my memory usage shoots up nearly 500 MB. This is running on macOS 10.14.6
    o
    • 2
    • 16
Powered by Linen
Title
s

Sam Schilling

09/06/2019, 4:38 PM
Has anyone else experienced issues with NSObjects not being deallocated properly? I have a function that is called in a loop which allocates an NSObject (NSProcessInfo) but it never gets deallocated My loop runs for 150 ms and during that time application memory usage typically rises by ~50 MB, and when profiling I see it is because there are thousands of NSProcessInfo objects that never get deallocated (each one is only 4 KB)
fun elapsedRealtime() = (NSProcessInfo().systemUptime * 1_000)

val startTime = elapsedRealtime()
var currentTime = startTime
while (currentTime - startTime < 150) {
    currentTime = elapsedRealTime()
}
I would think NSProcessInfo objects should automatically be deallocated each time
elapsedRealtime
completes since the reference count would be 0, but I am unsure how Kotlin’s GC interacts with Swift/Objective-C’s ARC If I change the loop to run for 25 seconds for example my memory usage shoots up nearly 500 MB. This is running on macOS 10.14.6
FWIW, I was able to greatly decrease the memory footprint by surrounding the function in an autorelease pool, but it still seems to hold onto a bunch of the objects without releasing, just less than before
fun elapsedRealTime() = autoreleasepool { NSProcessInfo().systemUptime * 1_000 }
In this case I can run for 25 seconds and only increase memory by about 7 MB (as opposed to 500 MB previously), but still that 7 MB never goes away after the fact
o

olonho

09/06/2019, 5:35 PM
insert GC call
<https://github.com/JetBrains/kotlin-native/blob/8e0e346492436cc9c40d87f38926e841954d1d4e/runtime/src/main/kotlin/kotlin/native/internal/GC.kt#L30>
if you need to force collection, K/N uses delayed reference counter, so some memory may add up
s

Sam Schilling

09/06/2019, 6:22 PM
@olonho I have tried that and it does not free up any of the memory
I even tried calling
GC.start()
first since it says collect will not do anything if it is stopped
o

olonho

09/06/2019, 6:30 PM
How do you measure?
s

Sam Schilling

09/06/2019, 6:31 PM
Mac Activity Monitor
Shows the memory gradually go up to 500 MB as soon as my loop starts, and the program continues to execute afterwards but memory never goes down even after GC collect call
I am writing a framework that is used in Swift as well and using the Xcode profiler to view allocations I see that the
@autoreleasepool content
section is never cleared
@olonho Created a gist, maybe you can try to reproduce with it? https://gist.github.com/sschilli/5692c4582a85daec9a3ace186d8b431c
I just came across something interesting… if I call
GC.collect
after the loop body, memory usage grows very quickly, up to 500 MB:
while (currentTime - startTime < 25_000L) {
    currentTime = timer.elapsedRealtime()
}
GC.collect()
However if I call it inside the loop body, it grows much slower, up to only 8 MB by the time 25 seconds expires:
while (currentTime - startTime < 25_000L) {
    currentTime = timer.elapsedRealtime()
    GC.collect()
}
Can anyone explain this disparity?
@olonho I didn’t think GC.collect would be context dependent?
Seems to imply a memory leak
Either way though memory usage continues to grow unbounded despite GC.collect call, just because NSProcessInfo isn’t deallocated properly
o

olonho

09/07/2019, 8:08 AM
Please file an issue, but note, that macOS memory manager doesn’t guarantee, that even after freeing OS footprint reduces, so real marker if leak is evergrowing memory usage or seen in analysis by tools like valgrind
View count: 5