Friday, May 22, 2020
Understand and Prevent Memory Leaks in Delphi
Delphis support for object-oriented programming is rich and powerful. Classes and objects allow for modular code programming. Along with more modular and more complex components come more sophisticated and more complex bugs. While developing applications in Delphi is (almost) always fun, there are situations when you feel like the whole world is against you. Whenever you need to use (create) an object in Delphi, you need to free the memory it consumed (once no longer needed). Surely, the try/finally memory guarding blocks can help you prevent memory leaks; its still up to you to safeguard your code. A memory (or resource) leak occurs when the program loses the ability to free the memory it consumes. Repeated memory leaks cause the memory usage of a process to grow without bounds. Memory leaks are a serious problem -- if you have a code causing memory leak, in an application running 24/7, the application will eat up all the memory available and finally make the machine stop responding. Memory Leaks in Delphi The first step to avoiding memory leaks is to understand how they occur. What follows is a discussion on some common pitfalls and best practices for writing non-leaking Delphi code. In most (simple) Delphi applications, where you use the components (Buttons, Memos, Edits, etc.) you drop on a form (at design time), you do not need to care too much about memory management. Once the component is placed on a form, the form becomes its owner and will free the memory taken by the component once the form is closed (destroyed). Form, as the owner, is responsible for memory deallocation of the components it hosted. In short: components on a form are created and destroyed automatically Examples of Memory Leaks In any non-trivial Delphi application, you will want to instantiate Delphi components at run time. You will, also, have some of your own custom classes. Lets say you have a class TDeveloper that has a method DoProgram. Now, when you need to use the TDeveloper class, you create an instance of the class by calling the Create method (constructor). The Create method allocates memory for a new object and returns a reference to the object. varzarko : TDeveloperbeginzarko : TMyObject.Create;zarko.DoProgram;end; And heres a simple memory leak! Whenever you create an object, you must dispose of the memory it occupied. To free the memory an object allocated, you must call the Free method. To be perfectly sure, you should also use the try / finally block: varzarko : TDeveloperbeginzarko : TMyObject.Create;tryzarko.DoProgram;finallyzarko.Free;end;end; This is an example of safe memory allocation and deallocation code. Some words of warning: If you want to dynamically instantiate a Delphi component and explicitly free it sometime later, always pass nil as the owner. Failure to do so can introduce unnecessary risk, as well as performance and code maintenance problems. Besides creating and destroying objects using the Create and Free methods, you must also be very careful when using external (files, databases, etc) resources.Lets say you need to operate on some text file. In a very simple scenario, where the AssignFile method is used to associate a file on a disk with a file variable when you are finished with the file, you must call CloseFile to free the file handle to begin used. This is where you do not have an explicit call to Free. varF: TextFile;S: string;beginAssignFile(F, c:\somefile.txt) ;tryReadln(F, S) ;finallyCloseFile(F) ;end;end; Another example includes loading external DLLs from your code. Whenever you use LoadLibrary, you must call FreeLibrary: vardllHandle : THandle;begindllHandle : Loadlibrary(MyLibrary.DLL) ;//do something with this DLLif dllHandle 0 then FreeLibrary(dllHandle) ;end; Memory Leaks in .NET? Although with Delphi for .NET the garbage collector (GC) manages most memory tasks, it is possible to have memory leaks in .NET applications. Heres an article discussion GC in Delphi for .NET. How to Fight Against Memory Leaks Besides writing modular memory-safe code, preventing memory leaks can be done by using some of the third-party tools available. Delphi Memory Leak Fix Tools help you catch Delphi application errors such as memory corruption, memory leaks, memory allocation errors, variable initialization errors, variable definition conflicts, pointer errors, and more.
Friday, May 8, 2020
Analysis Of Oedipus The King - 1571 Words
ââ¬Å"The only thing worse than being blind, is having sight with no visionâ⬠. This quote by American author Helen Keller perfectly captures the main characters journey in the play Oedipus the king by Sophocles. In this play the reader finds out that to see the truth one does not have to have eyes but have an open mind. The reader learns this through the quest the main character takes to solve a mystery in his kingdom. The main character, Oedipus is the king of a Greek city called Thebes who was from Corinth. He came to Thebes because there was prophecy stating that he would kill his father and marry is mother, so he left for Thebes where he solved the riddle and took the crown. While Oedipus was the kings, the city of Thebes fell into bad timesâ⬠¦show more contentâ⬠¦As the play continues Oedipus once again calls for a seer but this time he called for the oracle of Delphi, Teiresias. During this encounter many things go wrong that reveal how little knowledge Oedipus has of his past and the situation the city is in. The oracle Delphi is blind only being able to see what he prophesizes or has the knowledge about. In this situation the oracle knows that the corruption of the land is Oedipus while he doesnââ¬â¢t or doesnââ¬â¢t want to believe it. Oedipus asks the oracle for the answer but Teiresias doesnââ¬â¢t want to say anything because what he knows is worse for Oedipus than not knowing the truth. This is another case where not having knowledge makes you blind like Oedipus but having knowledge can make you see like the oracle even though he is physically blind. Tiresias says ââ¬Å", how terrible-to see the truth is only pain to him who sees (line, 359)!â⬠in this quote he tries to explain that because Oedipus canââ¬â¢t see the truth he canââ¬â¢t feel the pain that comes with it be if he could he would understand why itââ¬â¢s painful. The seer believes this so much that he says ââ¬Å"just send me home. You bear your burdens, ill bear mine. Itââ¬â¢s better that way, please believe me (line 363).â⬠After the oracle says this to Oedipus, he becomes even more blind but instead of being blind because he has no knowledge itââ¬â¢s because heââ¬â¢s blind with anger. Oedipus adds beingShow MoreRelatedAnalysis Of Oedipus The King 1127 Words à |à 5 Pages For A Life Of Regrets Oedipus the King is a play written by Sophocles. Oedipus is the main figure and legend of Sophocles play. After Oedipus birth into the world, his father King Laius of Thebes heard from a prophet that his own child was destined to kill him. Sophocles play begins from past to present and starts to unravel the journeys Oedipus goes through. Oedipus isn t an evil character as one would think while reading the story. He neverRead MoreAnalysis Of Oedipus Oedipus The King 1152 Words à |à 5 Pagesreading Oedipus the King. The number of times the words ââ¬Å"seeâ⬠or ââ¬Å"blindâ⬠are in the play make it make it undeniably obvious that they are significant. The theme is developed throughout the dialogue, through characters such as Tiresias and Oedipus, and also directly in the irony of the play. It is important in a play about the truth because almost every character was ââ¬Å"blindâ⬠to the truth. All of the characters, except one, can physically see, bu t mentally cannot see the truth. Oedipus seems toRead MoreCritical Analysis Of Oedipus The King1025 Words à |à 5 PagesCritical Analysis: Oedipus the King Oedipus the King is a tragic play showing a shift from the belief of fate to freedom of choice. Therefore, Oedipus the king is a great example of those who run from fate ends up fulfilling their fate After reading this type of tragic play ââ¬Å"Oedipus the Kingâ⬠written by Sophocles you can see that the author did a very outstanding form of presenting a tragedy that has the characteristics of mimesis and a tragic hero. Specifically, the writer written the playRead MoreOedipus the King Character Analysis1321 Words à |à 6 PagesLancaster ENG230 11/25/2010 Oedipus the King Character Analysis Oedipus the King had accomplished many great things during his reign of Thebes and in his life time. Oedipus found out during his reign in Thebes that the Gods who loved him also knew his devastating fate. As a young man when Oedipus answered the riddle the Sphinx he soon found his self having everything want and need. He earned his spot as the new King of Thebes, he had a great wife and lovely set of childrenRead MoreAnalysis Essay: Oedipus the King1017 Words à |à 4 Pages Casual Analysis Essay: Oedipus the King Sophocles play Oedipus the King has endured for over two thousand years. The plays lasting appeal may be attributed to the fact it encompasses all the classical elements of tragedy as put forth by Aristotle in Poetics nearly a century before it was written. According to Aristotle, tragedy needs to be an imitation of life according to the law of probability or necessity. Tragedy is serious, complete, and has magnitude. It must have a beginning, middleRead MoreOedipus The King Character Analysis1429 Words à |à 6 Pages Mrs. Long-Goldberg Honors World Lit/Comp 26 September, 2017 Ignorance Can Lead to Great Agony Plays were of great importance in early Greek culture. Plays were the main source of entertainment, and one of the most prominent examples is Oedipus the King written by Sophocles. The drama is uplifted by the character development and excellent structure Sophocles has put forward. Interactions between characters and each characterââ¬â¢s motivations generate brilliant themes throughout the play. SophoclesRead MoreCharacter Analysis Of Oedipus The King1419 Words à |à 6 PagesAdhikari Mrs. Long-Goldberg Honors World Lit/Comp 26 September, 2017 Ignorance Can Lead to Great Agony Plays were of great importance in early Greek culture. Plays were the main source of entertainment, and one of the most prominent examples is Oedipus the King written by Sophocles. The drama is uplifted by the character development and excellent structure Sophocles has put forward. Interactions between characters and each characterââ¬â¢s motivations generate brilliant themes throughout the play. SophoclesRead MoreOedipus The King Analysis1357 Words à |à 6 PagesThe Greek play, Oedipus the King, shows how easy it is for a man to fall apart, while trying to make things right. Sophoclesââ¬â¢ tragedy tells the story of Oedipus, a regular man turned king of Thebes. Throughout the tragedy, Oedipus searches for the cause of the chaos and havoc encompassing his land; however, he discovers that he is the one responsible for the hardships plaguing Thebes. As the tragedy continues, Sophoclesââ¬â¢ exposes a dark side to power, fame, and ambition. Further, Sophoclesââ¬â¢ expose sRead MoreAnalysis Of Oedipus The King 1696 Words à |à 7 PagesDaKan Wei Professor Annjeanette Wiese HUMN 1110 1 October 2014 Fatalism in Oedipus the King Tragedy has always been considered the highest form of literature; Oedipus the King is written by Sophocles who is one of the three ancient Greek tragedians, it fully represents the enduring charm of the ancient Greek tragedy, leaving the reader endless thinking. Through Oedipusââ¬â¢ misfortune, Sophocles tries to reveal the cause of their tragedy is ubiquitous and ever-present fate,Read MoreAnalysis Of Oedipus The King1145 Words à |à 5 PagesOedipus goes against the Chorus as he strongly defends himself as the people intensify his incrimination of killing the old king. Oedipus could not believe in his wildest dreams that he murdered his own father and was the husband of his mother. As an adopted runaway boy and a newfound king, he had to dig deep in his past to ease his burden. The Chorusââ¬â¢ incrimination of the King has brought the town into a downward spiral due to finding the real truth of the blind prophet. The relevance of Oedipusââ¬â¢
Wednesday, May 6, 2020
A Belief Essay Free Essays
ââ¬Å"I believe in God, the Father Almightyâ⬠¦Ã¢â¬ starts the famous Catholic prayer, the Apostleââ¬â¢s Creed. And this is how I will also start this paper. I am not a very religious person but I do believe in a Supreme Being, in God, in an invisible an invincible hand that has created everything there is in on earth. We will write a custom essay sample on A Belief Essay or any similar topic only for you Order Now This belief of mine is probably one of the most difficult things to prove since no one has ever actually seen this God I am pertaining to. However, a lot of people share my belief and a proof of this is the many religions and religious sects all over the world. The world kneels down and prays. Most of us pray for ourselves, our families, our relatives, our neighbors, even for people we do not know, and even for our enemies. We say our graces before and after meals; we close our eyes and talk to God before we rest for the night; and we blurt out Godââ¬â¢s name when we are caught up in extremely tough situations. Why do we do these things? Itââ¬â¢s as if prayers are our e-mails, text messages, or phone calls to the God we cannot see but can only feel. We believe that somebody out or up there actually will read through our messages and reply or someone will answer our calls to listen to our pleas and eventually grant our wishes and fulfill our dreams. Even for not-so-religious or not-so-spiritual people, a simple ââ¬Å"Thank God! â⬠or ââ¬Å"Oh my God! â⬠is already an indirect or subtle acknowledgment that indeed there is a God. But where is God? Is he a male? Is she a female? Who knows? What I know is that when I was a kid, my Mom would always warn me to be good because someone up there in heaven is watching over my actions. So I came to believe that God lives in the heavens, smiling every time I am obedient but frowning in times I am naughty. As I grew older, I knew about the church, the sacred place for worship. It is here where people honor and praise God. A united community gathers and celebrates Godââ¬â¢s goodness. Prayers and songs of praise fill the air in glorifying Godââ¬â¢s name. But still, no physical being comes down from heaven to join in the holy celebration. Now that I am much wiser, I am told that I can find God in my fellowmen ââ¬â in my so-called brothers and sisters. God can actually be anyone from my Dad, to the cab driver, to my teacher, to a beggar, to a waiter, to whomever who does good deeds. God can be in disguise, in nameless faces, in unfamiliar places, in unexpected circumstances. Wherever happiness and goodness exist, God definitely exists. The Bible, which has existed since time immemorial, is a living proof of Godââ¬â¢s divine existence. Just like us today, the earliest people have felt Godââ¬â¢s presence in their lives. However, just like us as well, they only knew God as the creator, the Supreme Being, the higher one. Nobody knew Godââ¬â¢s ways ââ¬â how he/she looks, how he/she speaks, his/her mannerisms or hobbies, what have you. Except probably for films and TV shows that portray God either as an old man in a white shining robe or just plain white light, speaking in a mellow commanding voice, we know nothing of his/her true nature. What we know are the marvelous wondrous things God has done for us. I believe God knows what is best for each one of us thatââ¬â¢s why we call him/her the great provider who gives us only the things ââ¬â material or non-material, which we truly need. God is the hand that showers us with blessings. God is the light that guides every step or endeavor we take. God is the teacher who teaches us valuable lessons to learn in life. God is the kind heart that forgives all our shortcomings. God is the perfect epitome of how we should all live our lives. In my life, I always adhere to ââ¬Å"To see is to believe. â⬠But in the case of believing in God, not everything I do not see is unbelievable. I believe in God and will continue to do so. Why? Just simply call it faith. How to cite A Belief Essay, Essays
Subscribe to:
Posts (Atom)