Ryguyu
Ryguyu

Reputation: 173

Parse Image File persisting in app after deleted from parse backend

I am developing an app that uses parse to store and receive pictures. The pictures are taken on the phone, displayed on the app, saved in parse, and can be retrieved through Parse. I am fairly new to parse so i'm not sure if the following behavior is normal. When I download a picture from parse I am using the following code:

if let image1File = user?["image1"] as? PFFile {

image1File.getDataInBackgroundWithBlock {
        (imageData: NSData!, error: NSError!) -> Void in
        if !(error != nil) {
            imgOne.image = UIImage(data:imageData)
        }
    }
}

This code is in viewDidLoad so the picture will show when the viewController loads. However, when I manually delete the picture from parse myself, not through code, the picture persists and will continue to load until I delete the app from the simulator and reload it. Is this a parse/simulator/code issue?

Note: I am testing this on the simulator, not an actual phone

Thanks

Upvotes: 0

Views: 75

Answers (1)

C--
C--

Reputation: 16568

There could be several possible reasons for this to happen. First of all, Parse stores images in Amazon-S3 and what you essentially receive is an absolute link to that file. When you delete a parse object, that has a file reference attribute, the original file might not get deleted at all. That is why Parse has a Clear Unused Files from your Parse-app feature afterall.

Secondly, at several levels, images might be cached for obvious performance reasons. So, even if an image file is deleted, it persists at several locations for certain amounts of time, which might be another reason why you experience this issue.

But, from experience, you should code the logic in such a way that, if a particular object is deleted by the user, you should not pull anything related to that object the next time at all. Also, you may use a regular cron job to clean up unused files on your Parse-app.

Upvotes: 2

Related Questions