|
-
Nov 9th, 2006, 06:19 AM
#1
Thread Starter
Frenzied Member
Few questions.
Is there no Instr fucntion for VB 2005, if not would this roughly do the trick, havent' tested it?
VB Code:
Private Function Instr(byval TargetString as String, byval StringToFind as string) as Boolean
For i as integer = 1 to TargetString.length
If not StringToFind.length + i > TargetString.length then
If TargetString.substring(i,StringToFind.length) <> string.empty then
return true
exit for
End if
End if
Next
End Function
I looks like you dispose of objects now which completly erases them from memory, so what is the need for a ?
have they done away with API Dec's you just use Import now right as in C++ ?
Last edited by Jmacp; Nov 9th, 2006 at 06:23 AM.
-
Nov 9th, 2006, 06:32 AM
#2
Hyperactive Member
Re: Few questions.
To your first question,
you have the method IndexOf of the class string, that is overloaded in order to get more functionallity than with instr
The objects thats need to be disposed have a method call Dispose that free the resources used for this object.
Setting the variable that points to your object to nothing only do that, not free any resource, just makes your variable points to nothing.
hope this helps
-
Nov 9th, 2006, 07:39 AM
#3
Re: Few questions.
To elaborate on memory and resource management, setting a variable to Nothing and disposing an object are completely different and neither erases the object from memory.
The purpose of a Dispose method is to release unmanaged resources. That includes things like window handles for forms and controls, file handles for streams, etc. Because the .NET Framework manages memory automatically, objects may sit around in memory for some time after their usefulness has ended. Having those objects tie up valuable system resources is wasteful, so calling Dispose releases the resources immediately.
Setting a variable to Nothing removes that reference to the object from the system. Once there are no remaining references to an object it becomes eligible for garbage collection. The next time the garbage collector is invoked the memory that that object occupied can be reclaimed.
Setting a variable to Nothing is usually pointless in VB.NET. If the variable loses scope immediately or soon then the reference will be removed then anyway. You would only set a variable to Nothing if you have no further use for the object it refers to and the variable will not or may not lose scope fro some time. Note that setting a value type variable to Nothing is always pointless.
If you don't dispose an object that supports it, when the garbage collector comes to clean up that object it will be unable to. It must invoke the object's Finalize method to release its resources and then the object will remain in memory until the garbage collector makes another pass.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|