Comments (7)
Hi @mufumade, thank you for reaching us out!
I think we need more information about the way you use Carlos to be able to be able to identify the exact problem. Could you please answer on the following questions:
- How big are the images?
- From where do you execute your image downloading requests? Is it in
init
oronAppear
in your SwiftUI view? - Do you cancel redundant requests?
- Did you try to limit the memory cache capacity? I believe, by default the limit is 50MB.
from carlos.
Hey thanks for taking you time for my problem!
- All images are 500x500 px so not that large
- See in the updated issue
- I hope that canceling the publisher is enough?
- Soo in the updated issue you see that I directly interface with my S3CacheFetcher that's because when the images are already cached on the disk that I do not have a memory issue. I declared the cache static somewhere in my app as well with and without a memory or disk cache but when the image has to be downloaded the memory fills up and does not get released.
I hope you have all the information you need. And thanks again!
from carlos.
@mufumade I don't see any "obvious" problems in your code. I would suggest to limit MemoryCacheLevel
capacity to a smaller value (e.g. 20MB instead of default 50MB) and see if this helps. In the time being, I will investigate problem a bit deeper. Thanks!
from carlos.
@ivanlisovyi I have some updates for you. As you can see am decrypting my images after I downloaded them.
}else if let data = data{
if let imageData:Data = S3CacheFetcher.decryptImage(with: data, mediaItem: mediaItem){
promise(.success(imageData as NSData))
}
}
To Decrypt I am using CryptoKit.AES.GCM.
For some weird reason the memory goes up when I am decrypting data there.
....
if let error = error{
print(error)
promise(.failure(error))
}else if let data = data{
// Low memory usage
//promise(.success(data as NSData))
// ---
// High memory usage
let encrypt = try! AES.GCM.seal(data, using: S3CacheFetcher.symmetricKey).combined!
let decrypt = try! AES.GCM.open(AES.GCM.SealedBox(combined: encrypt), using: S3CacheFetcher.symmetricKey)
promise(.success(decrypt as NSData))
// ---
}
....
I have no idea why.. I am using the ConditionedOneWayTransformationBox
to decrypt images after the fetching cache level. This seams to work now.
from carlos.
@mufumade so, at the point where you resolve the promise you have your image data stored in memory 3 times: original image data you received from S3, encrypted data after seal
call and decrypted data after open
call. You can reduce peak memory usage by using autoreleasepool
autoreleasepool {
let encrypt = try! AES.GCM.seal(data, using: S3CacheFetcher.symmetricKey).combined!
let decrypt = try! AES.GCM.open(AES.GCM.SealedBox(combined: encrypt), using: S3CacheFetcher.symmetricKey)
promise(.success(decrypt as NSData))
}
from carlos.
Yes I tried that but the main problem I had is that the memory does not get released. And by not released I mean for ever. The memory usage just keeps climbing and climbing. What I would expect is that the memory only holds one image that is shown on the screen and getting released after the image disappears.
from carlos.
MemoryCache
will hold up to 50MB indefinitely by default. This is exactly the reason why I've suggested to limit MemoryCache
capacity in one of my previous comments.
from carlos.
Related Issues (20)
- Can't build with Carthage HOT 5
- Reify batchGetAll into a CacheLevel HOT 1
- Reify batchGetSome into a CacheLevel HOT 3
- Add identity cache (always missing) HOT 1
- Automatically expiring items based on lifetime HOT 4
- Migrate to Swift 2.3 HOT 2
- Migrate to Swift 3 HOT 8
- why it always occur like this " No such module PiedPiper ?" HOT 2
- setDataAsync assigns a negative value to an UInt causing runtime crash HOT 1
- Support for Gloss (Moya) HOT 5
- Problem running Carlos.playground
- Logger level capitalization
- Using Carlos to cache videos HOT 18
- Force to fetch from networking always HOT 4
- How can i implement fetch and refresh using cache
- Swift 4 Support HOT 2
- Minor Compiler Warnings for Swift 4.2 HOT 1
- App Distribution with Carlos dependency fails because of embedded PiedPiper
- How to remove specific Keys from the Cache without clearing all of them HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carlos.