7 Replies Latest reply: May 31, 2011 6:40 PM by safarmer RSS

    Memory freed

    858245
      I have to implement the file structure inside the applet. I have several elementary files under the dedicated file. It is defined that the memory has to be freed following the file deletion. I simple java it is sufficient to set the reference of the file object to null in order for the garbage collector to remove it. In the java card laguage what does it mean?
        • 1. Re: Memory freed
          safarmer
          It depends on your implementation but you could just mark the file as deleted and return the appropriate error if someone tries to access it. You should also set all the bytes to 0x00. If you post some code I could give you a more precise answer.

          Do not rely on the garbage collector :)

          Cheers,
          Shane
          • 2. Re: Memory freed
            816119
            In the java card laguage what does it mean?
            i think in javacard there are two cases:
            a. if garbage collector is not implemented on the card, it means nothing
            b. if garbage collector is implemented, it means nothing... unless you call JCSystem.requestObjectDeletion(), which is request for deleting unused objects
            • 3. Re: Memory freed
              safarmer
              666 wrote:
              b. if garbage collector is implemented, it means nothing... unless you call JCSystem.requestObjectDeletion(), which is request for deleting unused objects
              Which is not a good idea to rely on. You do not need this and it is inefficient

              Cheers,
              Shane
              • 4. Re: Memory freed
                816119
                Which is not a good idea to rely on. You do not need this and it is inefficient
                Please, explain why
                • 5. Re: Memory freed
                  safarmer
                  Because when the GC kicks in you have to wait for it to complete before anything can happen. This is because the JCVM is single threaded. The spec is also not clear about when this will happen. It just says
                  This method is invoked by the applet to trigger the object deletion service of the Java Card runtime environment. If the Java Card runtime environment implements the object deletion mechanism, the request is merely logged at this time_. The Java Card runtime environment must schedule the object deletion service prior to the next invocation of the Applet.process() method.
                  The JCVM spec also says:
                  Java Card technology, version 2.2.1 offers an optional, object deletion mechanism. Applications designed to run on these implementations can use the facility by invoking the appropriate API. See Application Programming Interface for the Java CardTM Platform, Version 2.2.1. But, the facility is only suitable for updating large objects such as certificates and keys atomically. Therefore, application programmers should conserve on the allocation of objects.*
                  As JC is an embedded environment, you need to be careful with dynamic memory allocation and garbage collection. How does your applet perform when the card fills up? Is it consistent or do you see random failures? Does the card still operate when it is full or does it become unresponsive. If you allocate your resources up front and do not rely on GC then you will have consistent behaviour. Your card will also run faster if it is not constantly doing memory allocations.

                  Cheers,
                  Shane
                  • 6. Re: Memory freed
                    Bluefairy
                    safarmer wrote:
                    You should also set all the bytes to 0x00.
                    Hi Shane,

                    As you know for big arrays (Suppose a 2000 byte array is allocated to implement a file tree and then a format command is issued) it does n't take a short time to set each byte of it to 0x00. Your suggestion is to do this or just set SOME bytes of array to 0x00 or something else?

                    -Thanks
                    • 7. Re: Memory freed
                      safarmer
                      If you want complete security you should wipe all bytes. If you are not concerned with complete security, just mark as deleted. It comes down to the tradeoff between performance and security.

                      Cheers,
                      Shane