Free the memory of a String

I am now creating a string object. I need to free the memory after using it,
I dereference it now like this:
String john = new String("John sucks");
john = null;
which doesn't free the memory the string object taken. Anybody have any suggestions of how to do it by using Garbage collection ? My friend told me that
a String object can be never removed from the memory, is it true or not?
Thank you very much

I am now creating a string object. I need to free the
memory after using it,
I dereference it now like this:
String john = new String("John sucks");
john = null;
which doesn't free the memory the string object taken.No it doesn't.
Anybody have any suggestions of how to do it by using
Garbage collection ? Forget about it.
My friend told me that
a String object can be never removed from the memory,
is it true or not?Did your friend not also tell you to not worry about it?
You have two strings.
1. The internal string represented by "John sucks"
2. A new string created by new String()
The first will not be cleaned (at least not without involved class loaders.)
The second will be cleaned when the garbage collector cleans it. Which it doesn't have to do until it feels like it.

Similar Messages

  • How and when does Berkeley free the memory of key and data ?

    Hi,
    even though i just have posted a question several days ago, i couldnt find an answere to these questions in the Berkeley docs or on the internet:
    Does Berkleley Db free the data that is handeled to it with the key or the data objekt ?
    When is it free?
    How is the data managed that is in the secondary databases which points directly to the primary database and do i have to copy it?
    It would be great to have some answeres, because its hard to write something with low memory use, when you dont know how the memory is treated.

    Hi,
    Does Berkleley Db free the data that is handeled to it with the key or the data objekt ?Records in the berkeley db is stored as 'Key' & 'Data' pair. The data is accessed into / from the db using the 'Key'. The data in the db is freed when it is deleted.
    When is it free?The data in the db is freed after 'delete' followed by 'checkpoint' operation.
    How is the data managed that is in the secondary databases which points directly to the primary database and do i have to copy it?The secondary database is just another regular database whose 'Key' is what you choose it to be and the 'Data' is the key in the primary database. The primary and secondary databases are connected using the DB->associate() call. More info with example on this is available here : [http://www.oracle.com/technology/documentation/berkeley-db/db/ref/am/second.html]
    Debsubhra Roy

  • How can we free the memory of array

    how can we refresh the memory of an array every time......if we want new values or fresh values each time.........becuase array index out of exception error is coming up and i want to deallocate the memory at the end of iteration or in the starting

    how can we refresh the memory of an array every
    time......if we want new values or fresh values each
    time.........becuase array index out of exception
    error is coming up and i want to deallocate the
    memory at the end of iteration or in the startingThis post consist of 95% gibberish. The only part that is not gibberish is "array index out of bounds exception" and that has nothing to do with memory at all.
    Please attempt to learn some basic Java before injuring yourself permanently.
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com . A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoritative than this.

  • How to free the memory after closing JavaFX Stage?

    I am creating a JavaFx application which contain a button. When I click on that button, it opens a new stage containing a table with thousands of data. It's working fine. But the problem is, when I close the Stage of that table, memory is not getting free by the application i.e. everytime when I open the new stage for table then memory is get increased. Is there any issue with JavaFX? or I have to do something else?
    I have tried to set everything null at the time of closing of that stage but still memory is not getting free.
    My button click code is :
    btn.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {
                    Stage stage = new Stage();
                    Table1Controller controller = (Table1Controller) Utility.replaceScene("/tablesample/Table1.fxml", stage);
                    controller.init(stage);
                    stage.setTitle("Sample");
                    stage.setWidth(583.0);
                    stage.setHeight(485.0);
                    stage.initModality(Modality.APPLICATION_MODAL);
                    InputStream in = TableSample.class.getResourceAsStream("icon_small.png");
                    try {
                        stage.getIcons().add(new Image(in));
                    } finally {
                        try {
                            in.close();
                        } catch (IOException ex) {
                    stage.show();
    Utility.replacescene method : It loads the scene from given fxml and set to stage. At final It return controller object for that scene.
    public static Initializable replaceScene(String fXml, Stage mystage) {
            InputStream in = null;
            try {
                FXMLLoader loader = new FXMLLoader();
                in = Utility.class.getResourceAsStream(fXml);
                loader.setLocation(Utility.class.getResource(fXml));
                loader.setBuilderFactory(new JavaFXBuilderFactory());
                AnchorPane page;
                try {
                    page = (AnchorPane) loader.load(in);
                } finally {
                    in.close();
                Scene scene = new Scene(page);
                mystage.setScene(scene);
                return loader.getController();
            } catch (Exception ex) {
                return null;
        }Thanks

    Is there any issue with JavaFX? or I have to do something else?It's likely an issue with your application code (though it could be a bug in the JavaFX platform too).
    Either way debugging most memory issues in JavaFX (except for ones the graphics card texture related) is the same as debugging them in Java - so just use standard Java profiling tools to try to track down any memory leaks you have.
    Such work is as much an art as a science and takes some experience to get right, so grab your detective cap, download and use the tools linked and try and track it down:
    http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java
    http://resources.ej-technologies.com/jprofiler/help/doc/indexRedirect.html?http&&&resources.ej-technologies.com/jprofiler/help/doc/helptopics/memory/memoryLeak.html
    http://www.ej-technologies.com/products/jprofiler/overview.html (recommended tool).
    http://visualvm.java.net/
    http://netbeans.org/kb/articles/nb-profiler-uncoveringleaks_pt1.html
    http://www.ibm.com/developerworks/library/j-leaks/ (this link is really old and somewhat outdated but explains some of the underlying concepts better than some newer articles I found).

  • How to free allocated memory

    As we all know in java the memory allocated for an object is freed automatically when there is no reference for that object exist. and there is no operator in java to free the memory explicitly like delete() in c++.
    But i want to free the memory allocated for the object in java for my project.
    but i dont know how to do this.
    Any idea abt this?

    ghanoz2480 wrote:
    emmmh,,,see the following documentation:
    [http://java.sun.com/javase/6/docs/api/java/lang/System.html#gc()|http://java.sun.com/javase/6/docs/api/java/lang/System.html#gc()]
    Edited by: ghanoz2480 on 10 Mei 09 6:58From your link:
    "Calling the gc method *_suggests_* that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects. "
    That does not guarantee that the gc will be run.
    As the OP has already said, and as Jos has already highlighted - what the OP wants to do cannot be done in java.

  • E-71 Storing Email to the Memory Card vs. Internal...

    Is it possible to store temporary email files (your Inbox for example) to the memory card as opposed to the internal phone memory?
    On multiple occasions, I've run out of memory on the phone when trying to process heavy amounts of work email. If the E71 can't process up to 100 emails per day, I might need to get rid of it and revert back to my Samsung Blackjack II.

    Try this:
    Go to messaging (envolope botton on the keyboard)
    Then Options.
    Then Select Settings
    Then Select Other
    Then Go to Memory in Use and Select Memory Card. The phone will ask you whether to transfer data to memory card, to which you should answer Yes. There is another question that is asks you ahead of moving which is "whether you want to keep original file".... You need to answer No to free the memory... if you don't do it, you have to go for a very tricky work-around to remove the file in phone memory.
    Good luck.

  • Flex strings never cleared from the memory

    I have this weird problem for a while and try to solve it to look up on the net for proper solution but still I am clueless.
    When I check my application's memory usage with flex profiler (4.6) the portion of String keep increasing and eventually reach the point of crash.
    And I pin pointed where this increasing occurs from my application's source code.
    It is the local string variable that I passed to Json.decode(). It never cleared.
    All the instance of the json string that I got from the socket server remains in the memory til app crashes even if profiler says there is 0 path to the String.
    I don't know how to clear these Strings. It only keeps growing.
    Please help me. I have been struggled with this for a week now.
    Thanks for any support in advance.
    ![enter image description here][1]
    portion of my source code that I think the source of the leak is as following.
       protected function evtserverReseved(event:ProgressEvent):void{
          var tmpArr:ByteArray = new ByteArray();
        var tempByteArray:ByteArray = new ByteArray();
        socEvtServer.readBytes(tmpArr, 0, socEvtServer.bytesAvailable);
         tempByteArray.writeBytes(leftOverMessageNotify, 0, leftOverMessageNotify.length);
        tempByteArray.writeBytes(tmpArr, 0, tmpArr.length);
        leftOverMessageNotify = new ByteArray();
        parseByteArray(tempByteArray); 
       private function parseByteArray(rawArray:ByteArray):void{
        if(( rawArray[0] == 0x30 || rawArray[0] == 0x31 ) && rawArray[1] == 0x00 ){
         var log:String = "";
         for(var i:int=0; i<16; i++){
          if(rawArray[i]==0){
          }else{
           log += rawArray[i]-48;
         sizeOfFullListNotify = uint(log);
         commonFunction.printLog("Event Server eventNotify sizeOfFullListNotify=" + sizeOfFullListNotify);
         rawArray.position = 16;
        var tempIdx:uint = rawArray.position;
        var tempLength:uint = rawArray.length;
        if(sizeOfFullListNotify <= tempLength - tempIdx){
         var tempArray:ByteArray = new ByteArray();
         var tempLeftOver:ByteArray = new ByteArray();
         var j:uint;
         for(j=0; j <sizeOfFullListNotify ; j++){
          tempArray[j] = rawArray[j+tempIdx];
         var euckrString:Object = tempArray.readMultiByte( tempArray.length,"euc-kr").replace(" ","").replace("\n","");
         //commonFunction.printLog("Total memory=" + flash.system.System.totalMemory +", Free memory=" + flash.system.System.freeMemory + ", Event Server eventNotify JSON 수신 data size=" +euckrString.toString().length+ ", body=" + euckrString.toString() );
          var ob:Object = com.adobe.serialization.json.JSON.decode(euckrString.toString());
         commonFunction.printLog("Total memory=" + flash.system.System.totalMemory +", Free memory=" + flash.system.System.freeMemory + ", Event Server eventNotify JSON data size=" +euckrString.length+ ", body=" + euckrString );
           if(ob.method != null){
          //gridBox.DT_HOUSE.addItemAt(ob,0);
          gridBox.DT_HOUSE.push(ob);
          totlaReceivedList++;
         }else if(!(ob.result is String)){
          //confirm for registerEventNotify
          commonFunction.printLog("confirm for registerEventNotify");
         if(sizeOfFullListNotify < tempLength - tempIdx){
          for(var k:uint=0; k <tempLength-tempIdx-sizeOfFullListNotify ; k++){
           tempLeftOver[k] = rawArray[k+j+tempIdx];
          parseByteArray(tempLeftOver);
         }else{
          //leftOverMessageNotify = new ByteArray();
        }else{
         //leftOverMessageNotify = rawArray;
         for(var i:int = 0 ; i<rawArray.length ; i++){
          leftOverMessageNotify[i] = rawArray[i];
         rawArray = null;
    var euckrString:Object(String) is the portion that never cleared from the memory.
    It keeps stacking till crashes.

    viseur has already been removed.
    you can always use:
    if(viseur&&viseur.stage){
    viseur.parent.removeChild(viseur);

  • If I download a song, album or playlist from iCloud to an iTunes Match enable device, can I delete the download at a later date if I need to free up memory on the device?

    If I download a song, album or playlist from iCloud to an iTunes Match enable device, can I delete the download at a later date if I need to free up memory on the device?

    Hi,
    Yes.
    JIm

  • The amount of free SGA memory available in the database

    Hi,
    How can we calculate the amount of free SGA memory available from the instance if the database is not set for Memory management.If the sga_max_size is set for a particular value and the db_cache_size and the shared_pool and all other components are specified,how can one determine whether all the memory allocated for SGA is in use?

    How can we calculate the amount of free SGA memory available from the instance if the database is not set for Memory management.When the SGA is allocated, the memory is fixed, and none of it is "free" really.
    how can one determine whether all the memory allocated for SGA is in use? Are you asking about usage WITHIN the pools? If so, shortly after startup the database buffer and shared_pool will fill-up and stay full . . . . .
    Here is the script that I use to see inside the data buffer contents:
    set pages 999
    set lines 80
    spool blocks.lst
    ttitle 'Contents of Data Buffers'
    drop table t1;
    create table t1 as
    select
    o.object_name object_name,
    o.object_type object_type,
    count(1) num_blocks
    from
    dba_objects o,
    v$bh bh
    where
    o.object_id = bh.objd
    and
    o.owner not in ('SYS','SYSTEM')
    group by
    o.object_name,
    o.object_type
    order by
    count(1) desc
    column c1 heading "Object|Name" format a30
    column c2 heading "Object|Type" format a12
    column c3 heading "Number of|Blocks" format 999,999,999,999
    column c4 heading "Percentage|of object|data blocks|in Buffer" format 999
    select
    object_name c1,
    object_type c2,
    num_blocks c3,
    (num_blocks/decode(sum(blocks), 0, .001, sum(blocks)))*100 c4
    from
    t1,
    dba_segments s
    where
    s.segment_name = t1.object_name
    and
    num_blocks > 10
    group by
    object_name,
    object_type,
    num_blocks
    order by
    num_blocks desc
    Hope this helps. . ..
    Don Burleson
    Oracle Press author

  • How to get the amount of free physical memory?

    How to get the amount of free physical memory?
    (without sudo or root)

    vmstat will give it to you.
    Although the question depends a bit on what you mean by free memory.
    The figure vmstat labels free (in any reasonably recent version of solaris) actually represents memory mostly filled with cached file contents. So it represents memory that can be easily released if needed by something more important.
    Like most unix versions, solaris will use any free memory to cache files thats have been read/written previously just in case they are needed again

  • Need to find the memory address of a buffer or string

    Two basic questions:
    -How does LabVIEW treat the concept of a "buffer"?  Isn't it just a string wired from one block to another?
    -How can I find the address of a memory location or buffer location?
    I am using the Call Shared Library Node to call two functions to unwrap a custom communication protocol packet.  I will be reading packets of information from the serial port and sending them through this unwrapper  The first function expects as the arguments a)the address of the buffer and b)the length (in bytes) of the buffer.  I can measure the length, but am unsure of the address.  I would have just wired the string output of the serial port to the input of the unwrapper, but the unwrapper wants the address of that string/buffer.  The data type of the buffer address that the function expects is "unsigned char*" in C++ which translates to "uInt8" in LabVIEW according to http://zone.ni.com/devzone/cda/tut/p/id/3009.  The second function that is being called writes the unwrapped data to the destination buffer address that I specify as an argument. 
    I located this VI that handles buffering, but am unsure how it would help me, because it doesn't deal with the address issue either (and it used arrays of doubles, not characters or strings which is what the output of the serial port will be).  http://zone.ni.com/devzone/cda/epd/p/id/2499
    Any help would be appreciated.
    Nathan
    Previous related post: Call Library Function Node: Instantiate a class/handle constructors in a C++ Shared Library?

    This question is probably better asked on the LabView forum.  I've never seen this type of question asked here.
    Duncan
    CVI user, even though I also have LabView ;-))

  • Upgraded to IO6, seems like the amount of system memory to run is higher, this causes issues with some Apps. I can't get SIRI to work because the amount of free system memory is not enough. how can I tell what is eating the system memory?

    Upgraded to IO6, seems like the amount of system memory to run is higher, this causes issues with some Apps. I can't get SIRI to work because the amount of free system memory is not enough. how can I tell what is eating the system memory?

    Upgraded to IO6, seems like the amount of system memory to run is higher, this causes issues with some Apps. I can't get SIRI to work because the amount of free system memory is not enough. how can I tell what is eating the system memory?

  • What is the best way to free up memory?

    Obviously emptying trash. But I have a couple large iMovie files -- from when I was assembling the movie, which is now complete and in a separate iTunes folder. I'm uncertain what will happen if I delete the original, which takes up a massive amount of space.

    memory or storage
    memory is mostly used when one are speaking about the working memory as how much Ram the computer has this of this as the kitchen table
    storage on the other hand is where data is stored think of this as the fridge
    if one wish to free up memory then one look in the dock and right click on the apps with a white dot under the icon they are programs running in the background taking up memory and choosing quit in the context menu
    if one wish to free storage one can uninstall big programs one does not need or delete as you say some movies or install packets in download or the likes

  • What is the best way to free up memory easily?

    what is the best way to free up memory easily? I have a fairly typical makeup of iTunes music, iMovie, iPhoto files, which is best to attack?
    Thanks

    If you're talking Hard Drive space, you'll want to start just by deleting the largest of files. Try removing movies first, as they're usually in the Gigs of data, since they contain video and audio. If you're storing original photos those can be as large as 8mb/each photo, and if you've taken hundreds, they add up quickly. Try saving them as smaller sizes, or deleting unwanted photos, and lastly, songs do take up space, but depending on the quality, duration and file type will be anywhere from 30kb to 10mb.
    Try removing some unneccesary applications too! Please let me know if I solved your question by using the buttons below, or reply to this thread if you need additional assistance.

  • When I delete files on a USB, it doesn't free up memory on the stik. I find I have to empty the entire stik, use Disk Utility to 'erase' it, then transfer back the files I removed to free up all the space on the stik. Is this the best practice?

    It frustrates me that if I delete a file from a USB, it doesn't free up the memory on the stik. I have been removing all the files from the stik, opening Disk Utility and erasing the empty USB. That frees up the entire stik. Then I have been transferring back the files I removed from the stik. The result is that I have memory available to use again. It seems to me this is an unnecessarily complicated and time consuming way to get the result. Is there a shorter way to do this?

    Hello Horst,
    Thank you for the question.  Have you been emptying your trash after deleting the items?  For the item to be removed from your USB device, you will need to empty the trash on your MacBook Pro after you delete the items, as described in the featured discussion below.  Your USB device will still need to be connected when you do this:
    Choose Empty Trash from the Finder menu. Unlike Windows, the trash needs to be emptied manually for any drive other than one mounted through the network.
    Can't delete off my USB drive
    https://discussions.apple.com/thread/1946841
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

Maybe you are looking for

  • Need Information regarding MDM

    Hello Friends, Basically I am a ABAP programmer.Now I want to learn MDM. Could you please let me know the following things. 1.What are the prerequisites to learn MDM. 2.Does it need any functional knowledge 3.Does MDM have good future. Thanks and Reg

  • Drop TS problem

    I have followed the below procedure to drop undo tablespace. SQL>alter tablespace undotbs1 offline; SQL>drop tablespace undotbs1 including contents and datafiles; But still the datafile exists at the operating system level and space is not released.W

  • What version of windows can i install?

    i am looking to install windows on my mac, however i only have 80GB left on my hard drive, i am aware that vista will have no problems installing but this uses 20GB minimum, and i believe XP only uses 5GB minimum of hard drive. the trouble i am havin

  • Meaningful Data from 'questions' - done in the form of a quiz

    I'm trying to get some meaning data from a quiz - currently i get back a series of numbers and commas - like this: Core Data "Status","Location","Raw Score","Max Score","Min Score","Time" "completed","4","0","0","0","00:00:18" That doesnt say how the

  • Syncing and Transferring to an Empty Library?

    What would happen if I transfered apps to an empty library? Would they saty on my iPod touch too or no? Same thing with syncing?