Reliability of protected void finalize() for freeing native dynamic memory

In different places, I've been reading different things about the specification of garbage collection in Java. From what I've found so far, it is pretty clear that if the garbage collector of the VM used decides to reclaim object X, then X.finalize() is called. However, opinions vary on whether the garbage collector will ever decide to reclaim X.
I'm using the JNI and, unfortunately, have to keep a few bits in memory on the native side. Even worse, I keep those bits in dynamic memory (allocated with C's malloc). These chunks of memory always correspond to a single object on the Java side, so I thought it would be a good idea to have my objects in the native interface include this bit of code:
native void free();
protected void finalize() throws Throwable {
  Exception x = null;
  try {
    free();
    /* whatever other destruction seems usefull */
  } catch(Exception e) {
    CentralHandler.handle(this, e);
    x = e;
  } finally {
    try {
      super.finalize();
    } catch(Exception e) {
      CentralHandler.handle(this, e);
      if(x != null)
        throw CentralHandler.combine(x,e);
}I have been told the problem with this is that I can't be sure the garbage collector will ever clear out this object, even when the program comes to an end (inside the VM; when the VM itself is killed, the user's on his own). Does it matter if finalize is never called and will all my malloc-ed memory just become free with the disappearance of the VM?

What you have been told about GC is correct: You should not depend on finalize for anything.
Assuming yours is a real-world program (and won't be graded), then if you are simply worried about memory being freed up when your program exits: Don't worry about it.

Similar Messages

  • Accesing from other classes to protected void

    Hy! I'm a newbie to java programming. So i am making a program in J2ME, and the problem is :
    I have an abstract class, wich i must extend. That class defines a procedure
    abstract protected void destroyApp(boolean unconditional), so in my extended class this void is protected. But i want to access to this procedure from other class, and do it somehow static.
    I have made a main program class (the extended class), and i want to send from other class a destroy message to it (to call destroyApp procedure).
    Kazhha.

    Your question has nothing to do with Native Methods.
    In the future, for novice questions, use the New To Java Technology forum.
    I have an abstract class, which i must extend. That
    class defines a procedure
    abstract protected void destroyApp(boolean
    unconditional), so in my extended class this void is
    protected.You can make the method public in your class.
    But i want to access to this procedure
    from other class, and do it somehow static.IIRC you cannot make a method static if it is not static in the class you extend.
    I have made a main program class (the extended class),
    and i want to send from other class a destroy message
    to it (to call destroyApp procedure).Huh?

  • The case for integrated, native physics in the Flash Runtime

    Hello everyone,
    As hopefully many of you know, a community based feature request page was created a few months back (Feature request for Flash and Air - uplist) and we've had a number of great ideas added and voted on.  In an attempt to better understand the individual requests, we thought we'd start threads on particular subjects to allow us to ask questions and get community feedback.  These posts should not be taken as a commitment to a particular feature (or lack of commitment to any other feature.)  I can't stress this enough.   I don't want anyone to think that we're ignoring other requests or to assume that because we're asking about something, they can expect to see this done in a future release.  We simply want to better understand the request so that we can reduce the number of assumptions on our part.
    To start, let's we've got a few questions regarding the request for "Integrated (native) physics" which currently has 142 votes.
    When talking about physics, are you interested in a 2D or 3D physics engine?
    Can you list native engines that demonstrate the features you want the Flash runtime to implement natively?
    For instance, if you're interested in Box2D functionality, have you tried http://www.box2dflash.org?
    Is there a huge performance gap between the native and ActionScript implementations of Box2D?
    Are you looking for solutions for desktop or mobile?
    Thanks,
    Chris

    I'm all for the addition of a native physics system, based on Box2D, that gives us native speed.
    But, I'd also like to suggest that you make sure that you are committed to polishing and improving the new API's, and not leave them stranded at v 1.0.
    For example, GameInput API is rife with bugs, and there seems to be no interest or pro-activeness on the part of Adobe to fix them. Zeh Fernando has put in a ton of work in standardizing the GameInput API, and he has been quite vocal about the issues, and as far as I know, no one from Adobe seems to care at all.
    Here's a link to his gitHub repo, where he lists current issues with the API:
    zeh/key-action-binder · GitHub
    know that Flash's GameInput API is still severely ridden with bugs. You may run into some of them. Here's some more information.
    Supported devices are not detected properly when added or removed (Bug #3709110): no workaround
    Using GameInput add Timer overhead every second in Windows (Bug #3660823): no workaround
    GameInput devices simply stop working when running on Android/OUYA: need to initialize things in the first frame of SWF (fixed in AIR 13.0.0.36/Flash Player 13.0.0.130?)
    Quick button presses may not be properly detected on Macs (Bug #3702039): no workaround (need to test sampling rate changes and if button activation can always be assumed from the up event)
    In addition to those, I have run into a major bug on nVidia Shield, creating huge lag in inputs. The bug is nearly 12mths old, and is very severe:
    Bug#3673122 - Shield controller massive lag
    I'd love to see the AIR team being much more pro-active about bug fixing. It seems to be like pulling teeth sometimes to actually get something fixed. I would think that the team, after putting in a big effort to implement GameInput in the first place, would be extremely pro-active in seeking out feedback and fixing the bugs in the first 3-6mths since release, to harden the API, but instead no one seems to care, and the onus is all on us to "file a bug report and vote", which seems code for "might get fixed, one day, maybe"
    We love AIR so much because of it's consistency, but new API's need to be as consistent as old ones, and need constant iteration and improvement as well. I know it's flashier to add a new bullet point to the marketing check list, but consistency and reliability are much more important in this chaotic and fragmented landscape.
    /2 cents

  • Would love Steve Jobs to contact me for in setting screen tinting orange for seizures as OK WE HAVE DONE IT AN ORANGE PROTECTIVE SCREEN OVERLAY FOR IPOD AND IPAD STOPPING JOHN'S photosensitivity SEIZURES AND STOPPING EYE PROBLEMS WITH USAGE

    OK WE HAVE DONE IT AN ORANGE PROTECTIVE SCREEN OVERLAY FOR IPOD AND IPAD STOPPING JOHN'S SEIZURES AND STOPPING EYE PROBLEMS WITH USAGE ABLE TO CUT ANY SIZE FOR PHONES EG
    Contact me Steve the idea is great and the pictures are reveal a better depth perception of colour call me a Mum that created a diffence for her son and kept him communicating on his ipod and his ipad proffessors were amazed at childrens hospital and would love to show you my ideas in making it built in to your ipod and ipads or any computer for that matter everyone i show is blown away not only that but a wider customer level will be reached from a Mum that made a difference for her son that was unable to communicate and then had seizures so developed my own cover that allows him to chat all day without having any eye problems.
    So we now sell the covers on ebay to help others access technology that they need in order to survive and live happily as without his ipod or ipad and him telling us what was wrong he would of died he had respritory lung disease photosensitive epilepsy a metabolic condition that could of killed him anytime from stroke or seizure battled with using all types of technology but now is a dream come true.
    Would love for this to be enabled in the setup of all computers alike to protect eyes and allow more users to speak and communicate a big thankyou to the creators and designers fabulous but please can you call me as this could make you even better i mean will and also give me more time.
    From one praying God fearing Mum
    Nadine
    Call me i do have better pics they were too big to upload orange covering on right hand side

    Going through the feedback and support pages will be a waste of your time. Apple won't respond to feedback, and support can't do anything regarding product suggestions, particularly not from a company with an existing product they wish to sell. The only attention you might get from Apple would be possible interest in selling your product through the Apple Stores, and I don't know how Apple chooses the third-party products they sell. All I could suggest would be writing to Apple's corporate headquarters:
    Apple
    1 Infinite Loop
    Cupertino, CA 95014
    with perhaps "Attention: Retail Sales Division" and telling them about your product and your interest in it being sold through the Apple Stores.
    Regards.

  • Protective screen needed for retina display?

    Is a protective screen needed for the 4S?

    I have a screen protector on my iPhone, it just makes me feel better because the screen is so beautiful I don't want it to get scratches. I have a zagg invisible shield on the front and back of my phone and love it!!

  • Does anyone know of a reliable / safe keyboard marco recorder for iMac?

    Does anyone know of a reliable / safe keyboard marco recorder for iMac?

    A Google search shows several models of 2Wire modems http://tinyurl.com/6wj3yb2 What model do you currently have & why do you want to replace it?
    I have ATT Uverse DSL & ATT provided their wireless router/modem. It's never failed during the years that I've used it (on 24/7).
     Cheers, Tom

  • Is there a protective travel case for the iPad2 that will cover the smart cover as well?

    Is there a protective travel case for the iPad2 that will cover the smart cover as well?

    There are a variety of well-made sleeves from SF Bags which will accommodate the Smart Cover. I'm partial to the neoprene bags and sleeves from Bult NY and I use this "hoodie" netbook sleeve (in black) for extra protection when I'm traveling or in the field because it has a rigid shell to protect the back and sides:
    http://www.builtny.com/hoodie-netbook-case-7-10-inches-prod.html
    For everyday, I slip my iPad, with the SmartCover on, into a small neoprene messenger bag, whose 6 pockets hold my iPad, a wireless keyboard (in a sleeve from SF Bags), Kindle, iPad, and cables /chargers:
    http://www.builtny.com/neoprene-messenger-bag-11-13-inches-prod.html

  • Workaround for opening a strongly typed cursor using native dynamic SQL

    Hi All,
    In reading the PL/SQL documentation for Oracle 9i, I noted that the OPEN-FOR
    statement with a dynamic SQL string only allows the use of weakly typed cursors.
    I have verified this limitation with my own experimentation as follows:
    DECLARE
    type rec_type is record(
    str     varchar2(40),
    num     number(22)
    type cur_type is ref cursor return rec_type;
    my_cur     cur_type;
    que     varchar2(100);
    tab     varchar2(40);
    BEGIN
    tab := 'dynamic_table_name';
    que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
    open my_cur for que;
    loop
    if my_cur%found then
    dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
    exit;
    end if;
    end loop;
    close my_cur;
    END;
    Running the above trivial example in an anonymous sql block yields the following
    errors as expected:
    ORA-06550: line 10, column 8:
    PLS-00455: cursor 'MY_CUR' cannot be used in dynamic SQL OPEN statement
    ORA-06550: line 10, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 13, column 54:
    PLS-00487: Invalid reference to variable 'MY_CUR'
    ORA-06550: line 13, column 7:
    PL/SQL: Statement ignored
    Is there a workaround to the situation? Since I do not know the table name at run
    time, I must use Native Dynamic SQL. I have a long and complex record type
    that I wish to return through JDBC using the REFCURSOR Oracle type in order to
    avoid having to register an inordinate number of OUT parameters. Moreover, I
    would like to return potentially one or more results in a ResultSet. Using the
    standard method of registering native SQL types for the IN and OUT bindings
    can only return one result. Hence the reason I would like to return a strong
    cursor type. Also, the type of query I am doing is complex, and needs to be
    executed in a PL/SQL procedure for performance reasons. Therefore simply
    executing a SELECT query dynamically built up on the the JDBC client won't
    do the trick.
    If anybody has experience with a similar problem and would like to volunteer
    information on their workaround, I would really appreciate it.
    Best Regards,
    J. Metcalf

    We can use strongly-typed REF CURSORs in DNS, but the typing derives from a table e.g.
    TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
    so the problem is your use of "return rec_type" bit.
    Forgive my bluntness but I think you have misunderstood strong and weak typing. You actually want to be using weakly-typed cursors. I mean this:
    Moreover, I would like to return potentially one or more results in a ResultSet. suggests that the structure of your resultset may vary, which is precisely what a weakly-typed ref cursor allows us to do. Then we can use the JDBC metadata methods to interrogate the structure of the resultset, innit.
    so try this:
    DECLARE
    type cur_type is ref cursor;
    my_cur cur_type;
    que varchar2(100);
    tab varchar2(40);
    BEGIN
    tab := 'dynamic_table_name';
    que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
    open my_cur for que;
    loop
    if my_cur%found then
    dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
    exit;
    end if;
    end loop;
    close my_cur;
    END;
    ras malai, APC
    Cheers, APC

  • Cancel Date in Void Checks for Payment

    Ver. 2005, PL11: The cancel date (and update date) is not being set when voiding a check for payment which is associated with an outgoing payment.
    Likewise, the cancel date (and update date) is not being set when a check for payment is voided when canceling an outgoing payment.
    When reporting on payment activity, the ocho file is not accurate without the cancel date. Any idea if this is a setting? A bug? Fixed in 2007? Ideas on a work-around?

    Ad-hoc payments, such as a cash on delivery order, an emergency employee loan or some other one-time payments are created using the check for payment screen, entered against an account number, not a vendor, and the "create journal entry" box is checked.
    The check is then immediately printed using the document printing. The payment wizard is invoked weekly, and it ignores these ad-hoc, paid and printed payments.
    Any ad-hoc checks for payment correctly have the cancel date and update date updated when using the void check for payment screen.
    Checks for payment created from the payment wizard (which are "associated" with a previously created outgoing payment) do not have the cancel date and update date updated in the check file (OCHO) when using the void check for payment screen.

  • I've authorized my computer but some files still protected and asking for aol account info which doesnt exist

    I just got a new computer and I'm bringing my music over.
    I authorized the new computer and imported my music. Most of my music is fine EXCEPT some items are still listed as protected and when I click on them it brings up the authorization dialog box. The problem is these files are looking for an AOL account, which I don't have. These files worked fine on my previous system.
    How to I get access to these protected files looking for a non-existant AOL account?

    http://www.apple.com/support/itunes/contact.html

  • WHERE CAN I FIND A RELIABLE 2x2GB SO DDR3 SDRAM FOR MY MACKBOOK?

    WHERE CAN I FIND A RELIABLE 2x2GB SO DDR3 SDRAM FOR MY MACKBOOK?

    Be sure when you buy RAM not to buy by spec.  Get RAM that specifically says MacBook mid-2010.  Not all 2x2GB SO DDR3 are the same.
    All of shldr2thewheel's sites offer you the option to buy by model and then age of model.

  • Why would a commercial printer ask for Illustrator native files instead of InDesign files?

    Why would a commercial printer ask for Illustrator native files instead of InDesign files?
    For example, We create 32 hang tags for the same brand. Each hang tag looks identical except for a color bar calling out the different fits. We set the files up in InDesign with a Master Page congaing all the similar artwork. This process saves us a lot of time when making changes to the entire package of hang tags. So my question is... why can't the printer use InDesign. They are saying they convert our InDesign files to Illustrator before printing.

    A printer who insists on native files but can't take InDesign is not properly equipped. It suggests they haven't updated their capabilities in 15 years.

  • Export 4k video for Facebook native video?

    Hi All,
    I am trying to export a 4k video to upload on facebook for its native video player.
    I have converted to mp4 the best suggested format but a crackling sound comes with it.
    Can anybody help?
    Thanks.

    Whether a 3.5mm "mini" jack or the older, larger 1/4" "phone" jack, the plug or "jack" can be either mono or stereo. A mono jack has a single "main" post for the sound signal, with an insulator near the end and a second bit of isolated metal for the tip as the "ground". A stereo jack has two sections in the "main" part, with a thin insulator between them, and the insulated tip ground.
    The socket the plug fits in can also be either stereo or mono. A mono socket will have only one post touching the main stem of the plug for signal, and a second post touching the tip for the ground. A stereo plug will have two posts touching the stem, one to receive left channel signals, one to receive right channel, and of course a third for the ground.
    If you look at the parts, you'll see that a standard mono plug will deliver signal to both left & right posts of the standard stereo socket. Most mono mics are wired this way. These you'll probably never need think about.
    The situation you're dealing with is that your mic is mono but uses a stereo jack, and is only wired to deliver to one channel ... which can be both useful and a total pain, depending on how well you're set up to utilize the options this can provide. Depending on adapters & cords, you can change this to deliver the same signal to both L & R, or you can use this mic and another one to deliver separate mics one to the left channel & another to the right channel, effectively giving you a second input on the one "channel".
    But what bits do you need?
    A stereo to mono adapter plug would take your current plug in one end, take the signals from "both" channels, combine & deliver that to a mono plug on the output end ... plug you mic into this, plug it into your recorder, and instantly your mic is being input into both channels of your recorder as this sort of adapter has a mono plug on it's output end. This is probably the simplest part to get you up & running now. Any local shop that sells electronic bits & pieces, like a shop for guitars & such, will have these in-stock and they're cheap.
    I also just got a couple mics that are mono but use a stereo jack with one channel "dark" ...dead ... unused. I'll be getting some adapters myself, probably just gaffer tape the things together.
    Neil

  • Password protect/disable printers for certain users under ML 10.8

    I am looking for a solution to prevent my youger pupils to print everything without asking me. Is there a solution to protect/disable printers for certain users under ML 10.8 ?

    Ok. The sharing interface is not robust enough (by itself) to password challenge print jobs. You may need to look at another printing technology known as CUPS. Apple created this for advanced print configuration, and it does offer Kerberos security with printing password challenges. I do not know if OS X server offers more granularity in configuration.
    I won't be able to help you with the following as I do not use the CUPS printing solution here.
    In Safari, type in the following and press return.
    localhost:631
    You will see a tabbed browser interface. And a bit of light reading ...

  • Is there a virus protection software available for the ipad 2?

    IS there any form of virus protection softward available for the ipad 2? Have seen AVG etc for ipad 2 talked about.

    It's not strictly correct to say there are no viruses or to be more accurate 'malware' for i-devices as there are
    There isn't. Provide links/proof if there are.
    If you really are an admin for McAfee then you should know what a virus is, and that there are none for iOS. If there were a virus for iOS it would be all over the news. It is also true to say there is no malware for stock iOS devices. If you've jailbroken your device, then maybe so, but you've purposefully put yourself at risk.
    hence the last 2 iOS updates which were patching various vulnerabilities.
    Yes, just like any OS, there have been vulnerabilities that, potentially, could be used for malware purposes, but iOS has been available for over 4 years and still not one virus or malware breakout. If you knew anything about the way iOS works, and how apps get approved, installed and run, you would know why a virus is virtually impossible, and even a trojan is very unlikely.
    Apple has a policy of never discussing security issues as they like to pretend that their products are totally immune, but they aren't.
    Like lots of companies, Apple don't discuss security vulnerabilities BEFORE they are fixed, because that would be irresponsible and make it easier for hackers to exploit. Apple have never pretended their products are totally immune. Use your brain, if Apple thought their products were immune, why would they release regular security updates?
    Companies like McAfee make money out of spreading FUD and making people believe they have to fork out lots of money for so-called "protection" that in most cases they don't need and doesn't work for unknown issues anyway. And now they're trying to prey on uninformed Windows users, who after years of being subjected to the real threat of viruses and malware now think they need the same for iOS devices.

Maybe you are looking for

  • Logic Channel Strip Instruments no longer open after Logic 8 upgrade

    I upgraded Logic 8.0 to 8.0.1 and now none of the preset Logic Channel strip instruments will open. I can open all of the instruments on their own no problem. But if I select something from one of their saved presets or an instrument that I've saved,

  • Putting sound in both channels

    I shot a video using a mic that only recorded in the left channel. How do I put sound in the right channel, as well? I this something I select when exporting the movie? If so, do I select "mono" or "stereo"? thanks.

  • Best Practice for Domain Controllers for a company of 500 users.

    Our company is expanding and is planning on having roughly 500 users managed by a domain controller. The question is, what sort of hardware do you actually need that will not be a bottleneck in the near future (3-5 years from now). We stick with Dell

  • Need help regarding with "\n"

    Hi, The application need to allow only printable characters, blank characters and \n-. For this purpose I have written the below regular expression. ^(\p{Print}|\p{Blank}|\n-)*$ exam = "this is for testing purpose message \n only"; regexp ="^(\p{Prin

  • Unable to get Office 2010 updates

    Dear Team I have windows 7 professional SP1 and Office 2010 ( Home and Business edition). In windows update I am getting only windows update & not office updates. All available options have failed. Microsoft chat agents several rimec checked my syste