admin 管理员组文章数量: 1086019
I have a variable oneDay
for which I have assigned an integer number
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
I'm releasing the memory occupied by oneDay
using the below syntax at the end of the function termination in which the code has been declared.
var oneDay=null;
The error that I'm getting :
error TS2134: Subsequent variable declarations must have the same type. Variable 'oneDay ' must be of type 'Date', but here has type 'null'.
What could be the possible solution for this??Thanks
I have a variable oneDay
for which I have assigned an integer number
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
I'm releasing the memory occupied by oneDay
using the below syntax at the end of the function termination in which the code has been declared.
var oneDay=null;
The error that I'm getting :
error TS2134: Subsequent variable declarations must have the same type. Variable 'oneDay ' must be of type 'Date', but here has type 'null'.
What could be the possible solution for this??Thanks
Share Improve this question edited Dec 23, 2014 at 5:38 Felix Kling 817k181 gold badges1.1k silver badges1.2k bronze badges asked Dec 23, 2014 at 4:44 forgottoflyforgottofly 2,72912 gold badges54 silver badges96 bronze badges 17- 6 Why do you think that's releasing memory? Just let it go out of scope. – Andrew Barber Commented Dec 23, 2014 at 4:45
- 5 You don't manually manage memory in JavaScript – Ryan Commented Dec 23, 2014 at 4:45
- 3 Why are you redeclaring oneday – Jain Commented Dec 23, 2014 at 4:47
- 1 What @Jain said; that's the actual cause of your error. – Andrew Barber Commented Dec 23, 2014 at 4:47
- 1 I'm not sure but it works for you $scope.days = null or delete $scope.days – Jain Commented Dec 23, 2014 at 4:53
2 Answers
Reset to default 8Memory is managed for you in JavaScript.
All modern browsers use a mark-and-sweep algorithm to detect unreachable objects (some older browsers use a reference-counting algorithm, which fails to collect objects where there is a reference loop as there will always be a reference) *.
As soon as an object can no longer be referenced it is eligible for garbage collection (although garbage collection will happen "at some point", not immediately).
On the whole, you don't need to concern yourself with memory management in JavaScript or TypeScript - unless you have a measurable problem.
(* From Pro TypeScript, p168-170)
Cause: You are re declaring this variable that why you are getting this error. Try this:
oneDay = null;
$scope.days = null
or
delete $scope.days
本文标签: javascriptMemory deallocation in TypeScriptStack Overflow
版权声明:本文标题:javascript - Memory deallocation in TypeScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743990913a2514706.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论